fcapy.ml.decision_lattice

This module provides ‘DecisionLatticeClassifier’ and ‘DecisionLatticeRegressor’ classes to use ‘ConceptLattice’ in a DecisionTree-like manner

Classes

DecisionLatticeClassifier([algo, ...])

A class which combines DecisionTree ideas with Concept Lattice to solve Classification tasks

DecisionLatticePredictor([algo, ...])

An abstract class to inherit 'DecisionLatticeClassifier' and 'DecisionLatticeRegressor' from

DecisionLatticeRegressor([algo, ...])

A class which combines DecisionTree ideas with Concept Lattice to solve Regression tasks

PredictFunctions(value)

An enumeration.

class fcapy.ml.decision_lattice.DecisionLatticeClassifier(algo='Sofia', use_generators=False, algo_params=None, generators_algo='approximate', random_state=None, prediction_func: PredictFunctions = PredictFunctions.AVGMAX)

A class which combines DecisionTree ideas with Concept Lattice to solve Classification tasks

fit(context)  :noindex:

Construct a concept lattice based on context and calculate interestingness measures to predict the context.target values (Inherited from DecisionLatticePredictor class)

predict(context)  :noindex:

Predict context.target labels based on context.data (Inherited from DecisionLatticePredictor class)

predict_proba(context)  :noindex:

Predict probabilities of context.target labels based on context.data

property algo_params

Dictionary of algorithm specific parameters

average_concepts_class_probabilities(concepts_i)

Average predictions of elements with indexes concepts_i to get a final probability prediction

average_concepts_predictions(concepts_i)

Average label predictions of elements with indexes concepts_i to get a final prediction

calc_concept_prediction_metrics(c_i, Y)

Calculate the target prediction for concept c_i based on ground truth targets Y

property class_names

Class names of the target values

compute_generators(context, algo, use_tqdm)

Compute generators of closed intents of concepts from the ConceptLattice

Parameters
  • context (FormalContext or MVContext) – A context to compute generators on

  • algo (str of {‘exact’, ‘approximate’}) – An algorithm to compute generators of closed intents. ‘exact’ works in exponential time but shows good result approximate works in a matter of milliseconds but shows awful result

  • use_tqdm (bool) – A flag whether to visualize the progress of the algorithm by tqdm bar

fit(context: MVContext, use_tqdm=False)

Fit a DecisionLattice to the context

Parameters
  • context (FormalContext or MVContext) – A training context. Target values should be kept in context.target property

  • use_tqdm (bool) – A flag whether to visualize algorithm progress with tqdm bar

property lattice

The ConceptLattice used by the DecisionLattice model

predict(context: MVContext, use_tqdm=False)

Use fitted model to predict target values of a context

Parameters
  • context (FormalContext or MVContext) – A context to predict

  • use_tqdm (bool) – A flag whether to visualize algorithm progress with tqdm bar

Returns

predictions – Prediction of target values for a given context

Return type

list of float

predict_proba(context: MVContext)

Predict a target probability prediction for objects of context context

shap_values(context: MVContext)

WARNING!!! The function does not return True shap_values. Just the first approximation

property use_generators

A flag whether to use closed intents of concepts (if set False) or their generators (o/w)

Can be changed after the model is fitted to the data

class fcapy.ml.decision_lattice.DecisionLatticePredictor(algo='Sofia', use_generators=False, algo_params=None, generators_algo='approximate', random_state=None, prediction_func: PredictFunctions = PredictFunctions.AVGMAX)

An abstract class to inherit ‘DecisionLatticeClassifier’ and ‘DecisionLatticeRegressor’ from

fit(context)  :noindex:

Construct a concept lattice based on context and calculate interestingness measures to predict the context.target values

predict(context)  :noindex:

Predict context.target variables based on context.data

property algo_params

Dictionary of algorithm specific parameters

average_concepts_predictions(concepts_i)

Abstract function to instantiate in subclasses. Calculate an average prediction of a subset of concepts

calc_concept_prediction_metrics(c_i, Y)

Abstract function to instantiate in subclasses. Calculate the concept measure used for target prediction

compute_generators(context, algo, use_tqdm)

Compute generators of closed intents of concepts from the ConceptLattice

Parameters
  • context (FormalContext or MVContext) – A context to compute generators on

  • algo (str of {‘exact’, ‘approximate’}) – An algorithm to compute generators of closed intents. ‘exact’ works in exponential time but shows good result approximate works in a matter of milliseconds but shows awful result

  • use_tqdm (bool) – A flag whether to visualize the progress of the algorithm by tqdm bar

fit(context: MVContext, use_tqdm=False)

Fit a DecisionLattice to the context

Parameters
  • context (FormalContext or MVContext) – A training context. Target values should be kept in context.target property

  • use_tqdm (bool) – A flag whether to visualize algorithm progress with tqdm bar

property lattice

The ConceptLattice used by the DecisionLattice model

predict(context: MVContext, use_tqdm=False)

Use fitted model to predict target values of a context

Parameters
  • context (FormalContext or MVContext) – A context to predict

  • use_tqdm (bool) – A flag whether to visualize algorithm progress with tqdm bar

Returns

predictions – Prediction of target values for a given context

Return type

list of float

shap_values(context: MVContext)

WARNING!!! The function does not return True shap_values. Just the first approximation

property use_generators

A flag whether to use closed intents of concepts (if set False) or their generators (o/w)

Can be changed after the model is fitted to the data

class fcapy.ml.decision_lattice.DecisionLatticeRegressor(algo='Sofia', use_generators=False, algo_params=None, generators_algo='approximate', random_state=None, prediction_func: PredictFunctions = PredictFunctions.AVGMAX)

A class which combines DecisionTree ideas with Concept Lattice to solve Regression tasks

fit(context)  :noindex:

Construct a concept lattice based on context and calculate interestingness measures to predict the context.target values (Inherited from DecisionLatticePredictor class)

predict(context)  :noindex:

Predict context.target labels based on context.data (Inherited from DecisionLatticePredictor class)

property algo_params

Dictionary of algorithm specific parameters

average_concepts_predictions(concepts_i)

Average label predictions of concepts with indexes concepts_i to get a final prediction

calc_concept_prediction_metrics(c_i, Y)

Calculate the target prediction for concept `c_i based on ground truth targets Y

compute_generators(context, algo, use_tqdm)

Compute generators of closed intents of concepts from the ConceptLattice

Parameters
  • context (FormalContext or MVContext) – A context to compute generators on

  • algo (str of {‘exact’, ‘approximate’}) – An algorithm to compute generators of closed intents. ‘exact’ works in exponential time but shows good result approximate works in a matter of milliseconds but shows awful result

  • use_tqdm (bool) – A flag whether to visualize the progress of the algorithm by tqdm bar

fit(context: MVContext, use_tqdm=False)

Fit a DecisionLattice to the context

Parameters
  • context (FormalContext or MVContext) – A training context. Target values should be kept in context.target property

  • use_tqdm (bool) – A flag whether to visualize algorithm progress with tqdm bar

classmethod from_decision_tree(dtree, context: MVContext, random_state=None)

Construct the DecisionLattice from the sklearn decision tree dt model fitted on context data

classmethod from_gradient_boosting(gb, context: MVContext)

Construct the DecisionLattice from the sklearn gradient boosting gb model fitted on context data

classmethod from_random_forest(rf, context: MVContext)

Construct the DecisionLattice from the sklearn Random Forest rf model fitted on context data

classmethod from_xgboost(xgb, context: MVContext)

Construct the DecisionLattice from the xgboost xgb model fitted on context data

property lattice

The ConceptLattice used by the DecisionLattice model

predict(context: MVContext, use_tqdm=False)

Use fitted model to predict target values of a context

Parameters
  • context (FormalContext or MVContext) – A context to predict

  • use_tqdm (bool) – A flag whether to visualize algorithm progress with tqdm bar

Returns

predictions – Prediction of target values for a given context

Return type

list of float

shap_values(context: MVContext)

WARNING!!! The function does not return True shap_values. Just the first approximation

property use_generators

A flag whether to use closed intents of concepts (if set False) or their generators (o/w)

Can be changed after the model is fitted to the data

class fcapy.ml.decision_lattice.PredictFunctions(value)

An enumeration.