### Install scikit-criteria Development Version from GitHub Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/install.rst Install the latest development version directly from the GitHub repository using pip. Useful for testing unreleased features. ```bash $ pip install git+https://github.com/quatrope/scikit-criteria/ ``` -------------------------------- ### Install scikit-criteria using Pip from PyPI Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/install.rst Install the package from the Python Package Index using pip. This is an alternative to conda installations. ```bash $ pip install scikit-criteria ``` -------------------------------- ### Create Decision Matrix Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/sufdom.ipynb Initializes a DecisionMatrix with criteria, objectives, alternatives, and the decision matrix values. This is the starting point for most analyses. ```python import skcriteria as skc dm = skc.mkdm( matrix=[ [7, 5, 35], [5, 4, 26], [5, 6, 28], [3, 4, 36], [1, 7, 30], [5, 8, 30], ], objectives=[max, max, min], alternatives=["PE", "JN", "AA", "FX", "MM", "FN"], criteria=["ROE", "CAP", "RI"], ) dm ``` -------------------------------- ### Install Mamba and scikit-criteria using Mamba Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/install.rst Install mamba for faster package management, then use it to install scikit-criteria from conda-forge. Recommended for Windows users. ```bash $ conda install -c conda-forge mamba $ mamba install -c conda-forge scikit-criteria ``` -------------------------------- ### Complete Custom Aggregation Model Example Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb This example demonstrates a complete custom aggregation model that assigns a rank of 1 to all alternatives and returns a dictionary with extra information. It requires the `numpy` library. ```python import numpy as np from skcriteria.mkagg import mkagg @mkagg def AllAlternativesAreFirst(alternatives, **kwargs): # Assign a rank of 1 to each alternative rank = [1] * len(alternatives) # Define extra information (example: some important value) extra = {"some_important_value": "the_important_value"} # Return the rank and extra information return rank, extra ``` -------------------------------- ### Install scikit-criteria using Conda Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/install.rst Use this command to install scikit-criteria from the conda-forge channel. It's recommended to use a new environment. ```bash $ conda install -c conda-forge scikit-criteria ``` -------------------------------- ### Initialize and Evaluate WeightedSumModel Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Initialize the WeightedSumModel and evaluate the decision matrix 'dmt' to get the ranking. The result object contains the ranking and other intermediate calculations. ```python dec = simple.WeightedSumModel() rank = dec.evaluate(dmt) # we use the tansformed version of the data rank ``` -------------------------------- ### Plot Ranking Bar Charts Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Generate both vertical and horizontal bar plots for rankings. Requires Matplotlib for figure and axes setup. ```python import matplotlib.pyplot as plt fig, axs = plt.subplots(1, 2, figsize=(20, 5)) rcmp.plot.bar(ax=axs[0]) rcmp.plot.barh(ax=axs[1]) fig.tight_layout(); ``` -------------------------------- ### Plot Ranking R2 Score and Distance Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Visualize the R2 score and distance metrics between rankings. Requires Matplotlib for figure and axes setup. ```python fig, axs = plt.subplots(1, 2, figsize=(19, 7)) for kind, ax in zip(["r2_score", "distance"], axs): rcmp.plot(kind, ax=ax) ax.set_title(kind.title()) fig.tight_layout() ``` -------------------------------- ### Plot Ranking Box Plots Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Create both vertical and horizontal box plots to visualize the distribution of rankings. Requires Matplotlib for figure and axes setup. ```python fig, axs = plt.subplots(1, 2, figsize=(20, 5)) rcmp.plot.box(ax=axs[0]) rcmp.plot.box(ax=axs[1], orient="h") fig.tight_layout(); ``` -------------------------------- ### Copying and Modifying Data Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Create a modified copy of the data object, for example, to change the names of alternatives. The original data object remains immutable. ```python dm = dm.copy(alternatives=["VW", "Ford"]) dm ``` -------------------------------- ### Load simple stock selection dataset and define pipeline Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Load a pre-defined decision matrix for stock selection and set up a TOPSIS pipeline with objective inversion and non-dominated filtering. ```python # Create a decision matrix for energy alternatives dm = skc.datasets.load_simple_stock_selection() # Define TOPSIS pipeline dmaker = mkpipe(InvertMinimize(), FilterNonDominated(), TOPSIS()) ``` -------------------------------- ### Import TOPSIS and Pipeline Utilities Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Import the TOPSIS method and the mkpipe function for creating pipelines. This is necessary for setting up the TOPSIS evaluation process. ```python from skcriteria.agg import topsis from skcriteria.pipeline import mkpipe ``` -------------------------------- ### Load Simple Stock Selection Dataset Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Loads the default simple stock selection dataset for demonstration purposes. ```python dm = skc.datasets.load_simple_stock_selection() dm ``` -------------------------------- ### Access WeightedSumModel Specific Scores Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Access the specific 'score' attribute from the intermediate calculators to get the numerical scores for each alternative. ```python rank.e_.score ``` -------------------------------- ### Create Alternatives vs Alternatives Matrices Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb Create pairwise comparison matrices for alternatives against each criterion. This involves creating a list of matrices, one for each criterion. ```python alt_vs_alt_by_crit = [ ahp.t([[1.0], [1.0 / 5.0, 1.0], [1.0 / 3.0, 3.0, 1.0]]), ahp.t([[1.0], [9.0, 1.0], [3.0, 1.0 / 5.0, 1.0]]), ahp.t([[1.0], [1 / 2.0, 1.0], [5.0, 7.0, 1.0]]), ] alt_vs_alt_by_crit ``` -------------------------------- ### Extending Aggregation and Transformation Models with Decorators Source: https://github.com/quatrope/scikit-criteria/blob/master/CHANGELOG.md Demonstrates how to use decorators to create custom aggregation and transformation models using functions. These decorators simplify the process of defining decision-making models. ```python >>> from skcriteria.extend import mkagg, mktransformer >>> >>> @mkagg >>> def MyAgg(**kwargs): >>> # Implementation of the aggregation function >>> >>> @mkagg(foo=1) >>> def MyAggWithHyperparam(**kwargs): >>> # Implementation of the aggregation function with >>> # hyperparameter 'foo' >>> >>> @mktransformer >>> def MyTransformer(**kwargs): >>> # Implementation of the transformation function >>> >>> @mktransformer(bar=2) >>> def MyTransformerWithHyperparam(**kwargs): >>> # Implementation of the transformation function with >>> # hyperparameter 'bar' ``` -------------------------------- ### Instantiate and Use StrFormat Transformer (Capitalize) Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb This snippet demonstrates instantiating the `StrFormat` transformer with a different string operation, `str.capitalize`, and applying it to the data matrix `dm`. ```python trans = StrFormat(operation=str.capitalize) trans ``` ```text Result: ]> ``` ```python trans.transform(dm) ``` ```text Result: Roe[▲ 2.0] Cap[▲ 4.0] Ri[▲ 1.0] Pe 7 5 0.028571 Jn 5 4 0.038462 Aa 5 6 0.035714 Fx 3 4 0.027778 Mm 1 7 0.033333 Gn 5 8 0.033333 [6 Alternatives x 3 Criteria] ``` -------------------------------- ### Importing TOPSIS and electre from skcriteria.madm Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/api/madm.rst Demonstrates how to import TOPSIS and electre from the deprecated skcriteria.madm package. This import is equivalent to importing from skcriteria.agg. ```python from skcriteria.madm.similarity import TOPSIS from skcriteria.madm import electre ``` -------------------------------- ### Define and evaluate TOPSIS pipeline Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Set up a pipeline using SumScaler, VectorScaler, and TOPSIS, then evaluate the decision matrix to obtain the initial ranking. ```python # Define TOPSIS pipeline dmaker = mkpipe( SumScaler(target="weights"), VectorScaler(target="matrix"), TOPSIS() ) # Get original ranking original_result = dmaker.evaluate(dm) display(original_result) ``` -------------------------------- ### Define a Custom Aggregation Model Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Declare a function with the desired model name using the CapWords convention. The `@mkagg` decorator registers it as a scikit-criteria model. This example shows a non-standard name that will trigger a warning. ```python from skcriteria.mkagg import mkagg @mkagg def bad_model_name(**kwargs): pass ``` -------------------------------- ### Import RanksComparator and mkrank_cmp Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Import the necessary classes for ranking comparison from the `skcriteria.cmp` module. ```python from skcriteria.cmp import RanksComparator, mkrank_cmp ``` -------------------------------- ### Create TOPSIS Pipeline Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Create a pipeline for TOPSIS that includes objective inversion, matrix scaling, weight scaling, and the TOPSIS method itself. This pipeline automates the data transformation and evaluation steps. ```python pipe = mkpipe( invert_objectives.NegateMinimize(), scalers.VectorScaler(target="matrix"), # this scaler transform the matrix scalers.SumScaler(target="weights"), # and this transform the weights topsis.TOPSIS(), ) ``` -------------------------------- ### Create Data object Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb Instantiate the Data object with the decision matrix, criteria types, and weights. ```python data = Data(mtx, criteria, weights) data ``` -------------------------------- ### Initialize RankTransitivityChecker Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Instantiate the RankTransitivityChecker with the decision maker pipeline and configure parameters like allow_missing_alternatives and max_ranks. ```python checker = RankTransitivityChecker( dmaker, allow_missing_alternatives=True, max_ranks=10 ) ``` -------------------------------- ### Instantiate and Use StrFormat Transformer (Default) Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb This snippet shows how to instantiate the `StrFormat` transformer with its default operation (lowercase) and then apply it to a data matrix `dm`. ```python trans = StrFormat() trans ``` ```text Result: ]> ``` ```python trans.transform(dm) ``` ```text Result: roe[▲ 2.0] cap[▲ 4.0] ri[▲ 1.0] pe 7 5 0.028571 jn 5 4 0.038462 aa 5 6 0.035714 fx 3 4 0.027778 mm 1 7 0.033333 gn 5 8 0.033333 [6 Alternatives x 3 Criteria] ``` -------------------------------- ### Load dataset and create MCDA pipeline Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Load the Van 2021 Evaluation Dataset and define an MCDA pipeline using `mkpipe` with specified preprocessing steps and the TOPSIS aggregation method. ```python # Load Van 2021 Evaluation Dataset of cryptocurrencies dm = skc.datasets.load_van2021evaluation(windows_size=7) # Create the MCDA pipeline dmaker = mkpipe( InvertMinimize(), SumScaler(target="weights"), VectorScaler(target="matrix"), TOPSIS() ) original_result = dmaker.evaluate(dm) display(original_result) ``` -------------------------------- ### Instantiate MaybeWSM with Default Hyperparameters Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Creates an instance of the MaybeWSM aggregation function with its default hyperparameter 'use_weights' set to True. ```python with_useweight = MaybeWSM() with_useweight ``` -------------------------------- ### Import Scikit-Criteria Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Import the Scikit-Criteria library, commonly aliased as `skc`. ```python import skcriteria as skc # we use skc as an abbreviation for scikit-criteria ``` -------------------------------- ### Import WeightedSumModel Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Import the WeightedSumModel from the skcriteria.agg module. This is the first step to use the Weighted Sum Model. ```python from skcriteria.agg import simple ``` -------------------------------- ### Compare Two Alternatives Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/sufdom.ipynb The `compare()` method allows for a detailed comparison between two specific alternatives, showing which criteria they are better, worse, or equal on. This is useful for understanding the nuances of dominance. ```python for dominant in dmf.dominance.dominators_of("FX"): display(dmf.dominance.compare(dominant, 'FX')) ``` -------------------------------- ### Import Preprocessing Modules Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Import the necessary InvertMinimize and SumScaler classes from the scikit-criteria preprocessing module. ```python from skcriteria.preprocessing import invert_objectives, scalers ``` -------------------------------- ### Define MCDM Pipelines Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Define three distinct MCDM evaluation pipelines using `mkpipe` for Weighted Sum, Weighted Product, and TOPSIS methods, including preprocessing steps like inverting objectives, filtering non-dominated alternatives, and scaling. ```python from skcriteria.pipeline import mkpipe from skcriteria.preprocessing.invert_objectives import ( InvertMinimize, NegateMinimize, ) from skcriteria.preprocessing.filters import FilterNonDominated from skcriteria.preprocessing.scalers import SumScaler, VectorScaler from skcriteria.agg.simple import WeightedProductModel, WeightedSumModel from skcriteria.agg.similarity import TOPSIS ws_pipe = mkpipe( InvertMinimize(), FilterNonDominated(), SumScaler(target="weights"), VectorScaler(target="matrix"), WeightedSumModel(), ) wp_pipe = mkpipe( InvertMinimize(), FilterNonDominated(), SumScaler(target="weights"), VectorScaler(target="matrix"), WeightedProductModel(), ) tp_pipe = mkpipe( NegateMinimize(), FilterNonDominated(), SumScaler(target="weights"), VectorScaler(target="matrix"), TOPSIS(), ) ``` -------------------------------- ### Load and Display Dataset Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Loads a simple stock selection dataset using scikit-criteria and displays the decision matrix. This is useful for testing custom aggregation models. ```python import skcriteria as skc dm = skc.datasets.load_simple_stock_selection() # load the dataset dm ``` -------------------------------- ### Create a decision matrix Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Construct a decision matrix with specified criteria, objectives, alternatives, and performance values for the MCDA problem. ```python # Create a decision matrix dm = skc.mkdm( matrix=[ [4.57, 4.64, 62.2, 43.8, 8.49, 65.7], [65.7, 67.3, 6.03, 43.8, 4.25, 9.42], [20.3, 14.0, 20.2, 6.25, 58.3, 20.3], [9.42, 14.0, 11.5, 6.25, 29.0, 4.57], ], objectives=[max, max, max, max, max, max], alternatives=["status quo", "oil & ev", "oil & ngv", "methanol"], criteria=["supply", "emission", "tech", "safety", "cost", "consumer preference"], ) ``` -------------------------------- ### Initialize Filter for Non-Dominated Alternatives Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/sufdom.ipynb Create an instance of `FilterNonDominated` to filter out dominated alternatives. Set `strict=True` to consider only strictly non-dominated alternatives. ```python flt = filters.FilterNonDominated(strict=True) flt ``` -------------------------------- ### Importing TOPSIS and electre from skcriteria.agg Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/api/madm.rst Shows the equivalent import statements using the skcriteria.agg package, which replaces the functionality of the deprecated skcriteria.madm package. ```python from skcriteria.agg.similarity import TOPSIS from skcriteria.agg import electre ``` -------------------------------- ### Create DecisionMatrix with Default Names Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Create a `DecisionMatrix` object using the `mkdm()` utility function with the matrix and objectives. Default names for alternatives and criteria will be used. ```python # we use the built-in function as aliases dm = skc.mkdm(matrix, [min, max, min]) dm ``` -------------------------------- ### Create and validate matrix with invalid Satty values Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb Demonstrates creating a matrix with an invalid Satty scale value and validating it, which results in a ValueError. ```python invalid_mtx = mtx.copy() invalid_mtx[0, 1] = 89 invalid_mtx ``` ```python ahp.validate_ahp_matrix(3, invalid_mtx) ``` -------------------------------- ### Import necessary libraries Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Import all required modules from scikit-criteria for creating decision matrices, pipelines, and performing transitivity checks. ```python import skcriteria as skc from skcriteria.pipeline import mkpipe from skcriteria.preprocessing.scalers import SumScaler, VectorScaler from skcriteria.preprocessing.invert_objectives import InvertMinimize from skcriteria.preprocessing.filters import FilterNonDominated from skcriteria.agg.similarity import TOPSIS from skcriteria.ranksrev.rank_transitivity_check import RankTransitivityChecker ``` -------------------------------- ### Create DecisionMatrix with Custom Names Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Create a `DecisionMatrix` object with custom names for alternatives and criteria. This improves readability and context. ```python dm = skc.mkdm( matrix, objectives, alternatives=["car 0", "car 1"], criteria=["autonomy", "comfort", "price"], ) dm ``` -------------------------------- ### Import necessary modules Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb Import the Data class and criteria types (MIN, MAX) from the skcriteria library. ```python from skcriteria import Data, MIN, MAX ``` -------------------------------- ### Identify Dominated Alternatives Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/sufdom.ipynb Use the `dominated()` method to find all alternatives that are dominated by at least one other alternative. The result is a boolean Series indicating whether each alternative is dominated. ```python dmf.dominance.dominated() ``` -------------------------------- ### Initialize RankTransitivityChecker Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Creates an instance of RankTransitivityChecker to perform transitivity evaluations. Allows configuration of parameters like max_ranks. ```python checker = RankTransitivityChecker(dmaker, allow_missing_alternatives=True, max_ranks=1000) # Run the transitivity evaluation results = checker.evaluate(dm=dm) display(results["Original"]) display(results["Recomposition1"]) ``` -------------------------------- ### Import ahp module Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb Import the ahp module to use its functions for creating and validating AHP matrices. ```python import ahp ``` -------------------------------- ### Create and validate matrix with non-reciprocal values Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb Shows how to create a matrix with non-reciprocal values and validate it, triggering a ValueError for asymmetry. ```python invalid_mtx = mtx.copy() invalid_mtx[0, 1] = 0.5 invalid_mtx ``` ```python ahp.validate_ahp_matrix(3, invalid_mtx) ``` -------------------------------- ### Evaluate and Display Rankings Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Evaluate the decision matrix using the defined pipelines and display the resulting rankings for Weighted Sum, Weighted Product, and TOPSIS methods. ```python wsum_result = ws_pipe.evaluate(dm) wprod_result = wp_pipe.evaluate(dm) tp_result = tp_pipe.evaluate(dm) display(wsum_result, wprod_result, tp_result) ``` -------------------------------- ### Initialize and evaluate RankInvariantChecker Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Wrap the MCDA method with `RankInvariantChecker` to assess rank stability by applying degradations to suboptimal alternatives. Set `repeat` to 2 and `allow_missing_alternatives` to True. ```python # Create the stability evaluator rrt1 = RankInvariantChecker( dmaker=dmaker, repeat=2, allow_missing_alternatives=True ) # Execute the RRT1 test comparison = rrt1.evaluate(dm) ``` -------------------------------- ### Load Decision Matrix Dataset Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Load a sample decision matrix dataset using `skcriteria.datasets.load_van2021evaluation` with a specified window size. ```python import skcriteria as skc dm = skc.datasets.load_van2021evaluation(windows_size=7) dm ``` -------------------------------- ### Run AHP Calculation Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb Execute the `ahp.ahp()` function with the created matrices to obtain the AHP results. This function returns the rank, points, and consistency indices/ratios. ```python result = ahp.ahp(crit_vs_crit, alt_vs_alt_by_crit) rank, points, crit_ci, avabc_ci, crit_cr, avabc_cr = result ``` -------------------------------- ### Instantiate MaybeWSM with Weights Disabled Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Creates an instance of the MaybeWSM aggregation function with the 'use_weights' hyperparameter explicitly set to False. ```python without_useweight = MaybeWSM(use_weights=False) without_useweight ``` -------------------------------- ### Instantiate AllAlternativesAreFirst Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Instantiate the AllAlternativesAreFirst aggregation method. ```python # Instantiate the new aggregation agg = AllAlternativesAreFirst() agg ``` -------------------------------- ### Create MCDA Pipeline Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/sufdom.ipynb Constructs a scikit-criteria pipeline for a full MCDA experiment. It includes filtering, objective inversion, scaling, and the TOPSIS method. Ensure necessary modules are imported. ```python from skcriteria.preprocessing import scalers, invert_objectives from skcriteria.agg.similarity import TOPSIS from skcriteria.pipeline import mkpipe pipe = mkpipe( filters.FilterGE({"ROE": 2}), filters.FilterNonDominated(strict=True), invert_objectives.NegateMinimize(), scalers.SumScaler(target="weights"), scalers.VectorScaler(target="matrix"), TOPSIS(), ) pipe ``` -------------------------------- ### Accessing Alternatives and Criteria Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Access the lists of alternatives and criteria names. These are fundamental identifiers for the data structure. ```python dm.alternatives, dm.criteria ``` -------------------------------- ### Identify Strictly Dominated Alternatives Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/sufdom.ipynb To find alternatives that are strictly dominated (i.e., dominated in all criteria), pass `strict=True` to the `dominated()` method. This helps in identifying alternatives that are unambiguously worse than others. ```python dmf.dominance.dominated(strict=True) ``` -------------------------------- ### Create DecisionMatrix with Weights Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Create a `DecisionMatrix` object including criterion weights. The `weights` parameter accepts a vector specifying the importance of each criterion. ```python dm = skc.mkdm( matrix, objectives, weights=[0.5, 0.05, 0.45], alternatives=["car 0", "car 1"], criteria=["autonomy", "comfort", "price"], ) dm ``` -------------------------------- ### Evaluate Decision Matrix with Weights Enabled Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Evaluates the preprocessed decision matrix using the MaybeWSM instance where 'use_weights' is True, producing a ranking. ```python rank_with_uw = with_useweight.evaluate(dm) ``` -------------------------------- ### Plotting Criteria and Weights Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Visualize the transformed decision matrix using Matplotlib. Plots KDE for criteria and bar chart for weights, with shared y-axis for comparison. ```python # we are going to user matplotlib capabilities of creat multiple figures import matplotlib.pyplot as plt # we create 2 axis with the same y axis fig, axs = plt.subplots(1, 2, figsize=(12, 5), sharey=True) # in the first axis we plot the criteria KDE dmt.plot.kde(ax=axs[0]) axs[0].set_title("Criteria") # in the second axis we plot the weights as bars dmt.plot.wbar(ax=axs[1]) axs[1].set_title("Weights") # adjust the layout of the figute based on the content fig.tight_layout() ``` -------------------------------- ### Rank Reversal Evaluation with RankInvariantChecker Source: https://github.com/quatrope/scikit-criteria/blob/master/CHANGELOG.md Shows how to use the RankInvariantChecker to evaluate rank reversal for a given decision matrix using a specific aggregation method like TOPSIS. This is useful for testing the stability of ranking methods. ```python >>> import skcriteria as skc >>> from skcriteria.cmp import RankInvariantChecker >>> from skcriteria.agg.similarity import TOPSIS >>> dm = skc.datasets.load_van2021evaluation() >>> rrt1 = RankInvariantChecker(TOPSIS()) >>> rrt1.evaluate(dm) ``` -------------------------------- ### Plot Ranking Regressions Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Run and visualize regressions on combinations of different rankings. Use `r2=True` to display R-squared values, formatted with `r2_fmt`. ```python rcmp.plot.reg(r2=True, r2_fmt=".3f"); ``` -------------------------------- ### Plotting Data with KDE Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Visualize the data distribution using a Kernel Density Estimate (KDE) plot. This plot shows the probability density of the data. ```python dm.plot("kde") ``` ```python dm.plot.kde() ``` -------------------------------- ### Print TOPSIS Results and Details Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Print the intermediate results of the TOPSIS evaluation, including ideal and anti-ideal solutions, and the similarity index. This provides detailed insights into how the ranking was determined. ```python print(rank.e_) print("Ideal:", rank.e_.ideal) print("Anti-Ideal:", rank.e_.anti_ideal) print("Similarity index:", rank.e_.similarity) ``` -------------------------------- ### Recomposition with Different Cycle-Breaking Strategies Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Performs recomposition using different cycle-breaking strategies ('random' and 'weighted') to generate alternative rankings. Accesses and displays the recomposed rankings. ```python # Recomposition using different cycle-breaking strategies # Use the default strategy (random) checker_random = RankTransitivityChecker( dmaker, cycle_removal_strategy="random", max_ranks=1 ) res_random = checker_random.evaluate(dm=dm) # Use the 'weighted' strategy checker_weighted = RankTransitivityChecker( dmaker, cycle_removal_strategy="weighted", max_ranks=1 ) res_weighted = checker_weighted.evaluate(dm=dm) # Access recomposed rankings rrandom = res_random["Recomposition1"] rweighted = res_weighted["Recomposition1"] display(original_result, rrandom, rweighted) ``` -------------------------------- ### Accessing Objectives Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Retrieve the objectives defined for each criterion. Objectives specify whether a criterion should be maximized (MAX) or minimized (MIN). ```python dm.objectives ``` -------------------------------- ### Plot Ranking Matrices (Heatmap, Covariance, Correlation) Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Visualize various ranking matrices using statistical heatmap-like plots. Supports 'heatmap', 'cov', and 'corr' types. ```python fig, axs = plt.subplots(1, 3, figsize=(19, 7)) for kind, ax in zip(["heatmap", "cov", "corr"], axs): rcmp.plot(kind, ax=ax) ax.set_title(kind.title()) fig.tight_layout() ``` -------------------------------- ### Scale Decision Matrix to [0, 1] Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Apply SumScaler to normalize the decision matrix values to a [0, 1] range. Use target="both" to scale both the matrix and weights. ```python scaler = scalers.SumScaler(target="both") dmt = scaler.transform(dmt) ``` -------------------------------- ### Display ranking comparison Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Iterate through and display the first few generated rankings from the transitivity checker results to compare different ordering outcomes. ```python display("Ranking Comparison") items = list(results.named_ranks.items()) for rank_name, ranking in items[:4]: display(ranking) ``` -------------------------------- ### Evaluate transitivity and recomposition consistency Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Run the checker's evaluate method on the decision matrix to obtain transitivity analysis results, including test criteria and break rates. ```python results = checker.evaluate(dm=dm) display("Transitivity Analysis Results:") display(f"Test Criterion 2 (Transitivity): {results.e_.test_criterion_2}") display(f"Test Criterion 3 (Recomposition Consistency): {results.e_.test_criterion_3}") display(f"Transitivity Break Rate: {results.e_.transitivity_break_rate:.4f}") ``` -------------------------------- ### TOPSIS with Custom Metric Hyperparameter Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Instantiates the TOPSIS aggregation function with a custom 'cityblock' metric hyperparameter. ```python topsis.TOPSIS(metric="cityblock") ``` -------------------------------- ### Display Alternative Ranks Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb View the calculated rank of each alternative. The output array indicates the order of preference, with lower numbers representing higher preference. ```python rank ``` -------------------------------- ### Visualize Dominance Matrix Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/sufdom.ipynb For large datasets, the dominance matrix can be visualized using the `plot.dominance()` method. This provides a graphical representation of the dominance relationships, aiding in quick analysis. ```python dmf.plot.dominance(strict=True); ``` -------------------------------- ### Create triangular matrix using ahp.t Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb Use the ahp.t function to create a complete AHP matrix from its lower triangular half, automatically calculating reciprocal values. ```python mtx = ahp.t([[1], [1.0, 1], [1 / 3.0, 1 / 6.0, 1]]) mtx ``` -------------------------------- ### Import necessary libraries Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Import the required modules from scikit-criteria and other libraries for data manipulation and visualization. ```python import skcriteria as skc from skcriteria.pipeline import mkpipe from skcriteria.preprocessing.scalers import SumScaler, VectorScaler from skcriteria.preprocessing.invert_objectives import InvertMinimize from skcriteria.agg.similarity import TOPSIS from skcriteria.ranksrev import RankInvariantChecker ``` -------------------------------- ### Access WeightedSumModel Alternatives Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Access the names of the alternatives from the result object using the 'alternatives' attribute. ```python rank.alternatives ``` -------------------------------- ### Evaluate with AllAlternativesAreFirst Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Evaluate the decision matrix using the AllAlternativesAreFirst method. ```python # evaluate rank = agg.evaluate(dm) rank ``` -------------------------------- ### Evaluate Original Ranking Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Evaluates the initial decision matrix to obtain the original ranking. This is a prerequisite for transitivity analysis. ```python original_result = dmaker.evaluate(dm) display(original_result) ``` -------------------------------- ### Create FilterGE for ROE >= 2 Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/sufdom.ipynb Creates a FilterGE (Greater or Equal) instance to filter alternatives where the 'ROE' criterion is 2 or higher. This is a convenient way to apply common inequality filters. ```python flt = filters.FilterGE({"ROE": 2}) ``` -------------------------------- ### Create RanksComparator with Explicit Ranks Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Use the RanksComparator class to create an instance by providing a sequence of tuples, where each tuple contains a name and its corresponding rank. An optional 'extra' dictionary can also be provided. ```python RanksComparator([("ts", tp_result), ("ws", wsum_result), ("wp", wprod_result)], extra={}) ``` -------------------------------- ### Evaluate MCDA Pipeline Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/sufdom.ipynb Applies the previously defined MCDA pipeline to the decision matrix 'dm'. This step executes the entire experiment, from filtering to final ranking. ```python pipe.evaluate(dm) ``` -------------------------------- ### Display Alternative Points Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb Examine the final points assigned to each alternative. These points represent the normalized scores derived from the AHP calculation. ```python points ``` -------------------------------- ### Find Dominators of a Specific Alternative Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/sufdom.ipynb Use the `dominators_of()` method to list all alternatives that strictly dominate a specified alternative. This is useful for understanding which alternatives are 'better' than a particular choice. ```python dmf.dominance.dominators_of("FX", strict=True) ``` -------------------------------- ### Display Full Dominance Matrix Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/sufdom.ipynb The `dominance()` method (or `dominance.dominance()`) generates a DataFrame showing the full dominance relationship between all alternatives. A `True` value indicates that the row alternative strictly dominates the column alternative. ```python dmf.dominance(strict=True) ``` -------------------------------- ### Calculate Kendall Correlation Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Calculates the Kendall correlation matrix between different ranking methods. Use the 'method' parameter to specify 'kendall'. ```python rcmp.corr(method="kendall") # or we can us the kendal correlation ``` -------------------------------- ### Create Criteria vs Criteria Matrix Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb Use `ahp.t()` to create a pairwise comparison matrix for criteria. This matrix is essential for the AHP calculation. ```python crit_vs_crit = ahp.t([[1.0], [1.0 / 3.0, 1.0], [1.0 / 3.0, 1.0 / 2.0, 1.0]]) crit_vs_crit ``` -------------------------------- ### Create RanksComparator by Inferring Names Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Use the mkrank_cmp function to create a RanksComparator instance where names are inferred from the provided methods. The 'extra' parameter is not needed in this case. ```python rcmp = mkrank_cmp(tp_result, wsum_result, wprod_result) rcmp ``` -------------------------------- ### Instantiate and Use StrFormat Transformer (Custom Function) Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb This snippet shows how to use a custom function `add_exclamation` with the `StrFormat` transformer to append exclamation marks to alternatives and criteria, and then apply it to the data matrix `dm`. ```python def add_exclamation(text): return text + " !! " trans = StrFormat(operation=add_exclamation) trans ``` ```text Result: ]> ``` ```python trans.transform(dm) ``` ```text Result: ROE !! [▲ 2.0] CAP !! [▲ 4.0] RI !! [▲ 1.0] PE !! 7 5 0.028571 JN !! 5 4 0.038462 AA !! 5 6 0.035714 FX !! 3 4 0.027778 MM !! 1 7 0.033333 GN !! 5 8 0.033333 [6 Alternatives x 3 Criteria] ``` -------------------------------- ### Define decision matrix Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb Create a list of lists to represent alternatives and their corresponding criteria values. ```python mtx = [ [1, 2, 3], # alternative 1 [4, 5, 6], # alternative 2 ] mtx ``` -------------------------------- ### Evaluate Decision Matrix with Weights Disabled Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Evaluates the preprocessed decision matrix using the MaybeWSM instance where 'use_weights' is False, producing a different ranking. ```python rank_without_uw = without_useweight.evaluate(dm) ``` -------------------------------- ### Evaluate TOPSIS Pipeline Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Evaluate the decision matrix 'dm' using the created TOPSIS pipeline. The pipeline sequentially applies all defined steps to produce the final ranking. ```python rank = pipe.evaluate(dm) ``` -------------------------------- ### Aggregation Function with Specific Parameters and **kwargs Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb A valid aggregation function can accept a subset of parameters along with variable keyword arguments (`**kwargs`) to handle any remaining parameters. ```python from skcriteria.mkagg import mkagg @mkagg def OnlyTwoWithKwargs(matrix, weights, **kwargs): pass ``` -------------------------------- ### Transform Matrix with Initial AsFloat Transformer Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Applies the `AsFloat` transformer to the decision matrix. Note that dtypes are preserved as integers. ```python trans.transform(dm) ``` -------------------------------- ### Display Transitivity Analysis Results Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Prints the results of the transitivity analysis, including specific test criteria and the transitivity break rate. ```python display("Transitivity Analysis Results:") display(f"Test Criterion 2 (Transitivity): {results.e_.test_criterion_2}") display(f"Test Criterion 3 (Recomposition Consistency): {results.e_.test_criterion_3}") display(f"Transitivity Break Rate: {results.e_.transitivity_break_rate:.4f}") ``` -------------------------------- ### Accessing the Data Matrix Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Access the data matrix, which contains the performance scores of alternatives across criteria. This matrix excludes objectives and weights. ```python dm.matrix # note how this data ignores the objectives and the weights ``` -------------------------------- ### Accessing Weights Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Retrieve the weights assigned to each criterion. Weights represent the relative importance of each criterion in the decision-making process. ```python dm.weights ``` -------------------------------- ### Plot Ranking Flow Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Visualize the flow of rankings. This is a common analysis for understanding how rankings change or are distributed. ```python rcmp.plot.flow(); ``` -------------------------------- ### Filter Alternatives with ROE > 3 and CAP > 4 Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/sufdom.ipynb Applies a FilterGT (Greater Than) to the original DecisionMatrix, filtering out alternatives where 'ROE' is greater than 3 AND 'CAP' is greater than 4. This demonstrates filtering based on multiple criteria simultaneously. ```python filters.FilterGT({"ROE": 3, "CAP": 4}).transform(dm) ``` -------------------------------- ### Plot Ranking Results with Confidence Intervals Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankrev.ipynb Generates a plot visualizing ranking results, including confidence intervals and a dashed line for mean ranks to highlight potential transitivity issues. ```python import matplotlib.pyplot as plt ax = results.plot() ax.plot( results[0], marker="o", linestyle="--", color="orange", label="Original results", zorder=3, ) ax.legend() plt.tight_layout(); ``` -------------------------------- ### Custom Aggregation Function with Hyperparameters Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Defines a custom aggregation function 'MaybeWSM' using the @mkagg decorator. It accepts 'use_weights' as a hyperparameter and applies weights conditionally. This function is designed for maximization objectives only. ```python import numpy as np from skcriteria.utils import rank @mkagg(use_weights=True) def MaybeWSM(hparams, matrix, objectives, weights, **kwargs): """The Maybe-Weighted Sum Model (WSM) to rank alternatives. If the use_weights parameter in hparams is set to True, the function applies weights to the decision matrix. """ # Check if objectives contain -1 (minimize objectives) if -1 in objectives: raise ValueError("'MaybeWSM' cant operate with minimize objectives") # If use_weights is True, apply weights to the matrix if hparams.use_weights: matrix = matrix * weights # Calculate the scores by row/alternative score = np.sum(matrix, axis=1) # rank_values calculates the ranking based on the scores. # `reverse = True` indicates that higher scores are closer to the 1st place. # Additionally, we will return the calculated 'score' as extra information. return rank.rank_values(score, reverse=True), {"score": score} ``` -------------------------------- ### Default TOPSIS Hyperparameter Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Instantiates the TOPSIS aggregation function with its default metric hyperparameter. ```python from skcriteria.agg import topsis topsis.TOPSIS() ``` -------------------------------- ### Import Filters Module Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/sufdom.ipynb Imports the necessary filters module from scikit-criteria for preprocessing and data cleaning tasks. ```python from skcriteria.preprocessing import filters ``` -------------------------------- ### Define criteria types Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb Specify whether each criterion is for maximization (MAX) or minimization (MIN). ```python # let's says the first two alternatives are # for maximization and the last one for minimization criteria = [MAX, MAX, MIN] criteria ``` -------------------------------- ### Define a New Aggregation Model Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb This Python code defines a new aggregation model by subclassing the `Aggregation` class. It requires implementing the `__call__` method to specify the aggregation logic. ```python from skcriteria.aggregation import Aggregation class MyAggregation(Aggregation): def __init__(self, name="my_aggregation"): super().__init__(name=name) def __call__(self, alternatives, criteria, dm, **kwargs): # Implement your aggregation logic here # This is a placeholder and should be replaced with actual calculations print(f"Aggregating {len(alternatives)} alternatives across {len(criteria)} criteria.") # Example: return a dummy result return [1.0] * len(alternatives) # Example usage: # my_agg = MyAggregation() # result = my_agg(alternatives, criteria, dm) ``` -------------------------------- ### Transform Decision Matrix to Eliminate Minimize Objectives Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Uses the InvertMinimize transformer to preprocess the decision matrix, ensuring all objectives are for maximization. ```python from skcriteria.preprocessing import invert_objectives dm = invert_objectives.InvertMinimize().transform(dm) ``` -------------------------------- ### Define a String Formatting Transformer Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb This snippet defines a custom transformer `StrFormat` that applies a given string operation to alternatives and criteria. It uses the `@mktransformer` decorator and expects a dictionary with 'alternatives' and 'criteria' keys in its return value. ```python from scikit_criteria.transforms import mktransformer @mktransformer(operation=str.lower) def StrFormat(alternatives, criteria, hparams, **kwargs): """Applies a string formatting operation (lowercasing by default) to alternatives and criteria.""" # Apply the string formatting operation to each alternative new_alternatives = [hparams.operation(a) for a in alternatives] # Apply the string formatting operation to each criterion new_criteria = [hparams.operation(c) for c in criteria] # Return the transformed alternatives and criteria in a dictionary return {"alternatives": new_alternatives, "criteria": new_criteria} ``` -------------------------------- ### Plotting Criterion Weights Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Visualize the weights of the criteria using a wheatmap plot. This helps in understanding the relative importance of each criterion. ```python dm.plot.wheatmap() ``` -------------------------------- ### Aggregation Function with All Parameters Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb A valid aggregation function can accept all decomposed decision matrix parameters: `hparams`, `matrix`, `objectives`, `weights`, `dtypes`, `alternatives`, and `criteria`. ```python from skcriteria.mkagg import mkagg @mkagg def AllParameters(hparams, matrix, objectives, weights, dtypes, alternatives, criteria): pass ``` -------------------------------- ### Calculate Covariance Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Calculates the covariance matrix between different ranking methods. ```python rcmp.cov() ``` -------------------------------- ### Default Data Plotting (Heatmap) Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Visualize the entire data structure using the default heatmap plot. This provides a visual overview of alternative-criterion scores. ```python dm.plot() ``` -------------------------------- ### Calculate Pearson Correlation Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Calculates the Pearson correlation matrix between different ranking methods. This is the default method used. ```python rcmp.corr() # by default the pearson correlation is used ``` -------------------------------- ### Validate a correct AHP matrix Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb Use ahp.validate_ahp_matrix to check if a given matrix conforms to AHP requirements (size and Satty scale values). ```python # this validate the data ahp.validate_ahp_matrix(3, mtx) ``` -------------------------------- ### Apply FilterGE to Decision Matrix Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/sufdom.ipynb Applies the previously defined FilterGE to the DecisionMatrix, removing alternatives that do not meet the 'ROE' >= 2 condition. The result is a new DecisionMatrix with filtered alternatives. ```python dmf = flt.transform(dm) ``` -------------------------------- ### Define a Transformer to Convert Criteria to Float Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Defines a custom transformer `AsFloat` that converts decision matrix elements to floating-point numbers. This initial version does not re-infer dtypes. ```python @mktransformer def AsFloat(matrix, **kwargs): """Converts the elements of a decision-matrix to floating-point numbers.""" # Convert the elements of the matrix to floating-point numbers new_matrix = matrix.astype(float) # Return the transformed matrix in a dictionary return {"matrix": new_matrix} trans = AsFloat() trans ``` -------------------------------- ### Accessing Extra Score Data Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/extend.ipynb Retrieves and displays the 'score' data, which is stored in the 'extra_' attribute of the ranking results, for both configurations of 'use_weights'. ```python rank_with_uw.e_.score, rank_without_uw.e_.score ``` -------------------------------- ### Convert to Pandas DataFrame Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/rankcmp.ipynb Converts the RankComparator object into a pandas DataFrame for easier data manipulation and analysis. ```python rcmp.to_dataframe() ``` -------------------------------- ### Define criteria weights Source: https://github.com/quatrope/scikit-criteria/blob/master/ahp_ext/tuto.ipynb Assign weights to each criterion, representing their relative importance. ```python # et’s asume we know in our case, that the importance of # the autonomy is the 50%, the confort only a 5% and # the price is 45% weights = [0.5, 0.05, 0.45] weights ``` -------------------------------- ### Access WeightedSumModel Method Name Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Access the name of the method used for ranking from the result object using the 'method' attribute. ```python rank.method ``` -------------------------------- ### Invert Minimization Criteria Source: https://github.com/quatrope/scikit-criteria/blob/master/docs/source/tutorial/quickstart.ipynb Use InvertMinimize to transform criteria that should be maximized. This prepares the data for consistent analysis by Scikit-Criteria. ```python inverter = invert_objectives.InvertMinimize() dmt = inverter.transform(dm) ```