fcapy.ml.decision_lattice
This module provides ‘DecisionLatticeClassifier’ and ‘DecisionLatticeRegressor’ classes to use ‘ConceptLattice’ in a DecisionTree-like manner
Classes
|
A class which combines DecisionTree ideas with Concept Lattice to solve Classification tasks |
|
An abstract class to inherit 'DecisionLatticeClassifier' and 'DecisionLatticeRegressor' from |
|
A class which combines DecisionTree ideas with Concept Lattice to solve Regression tasks |
|
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
contextand calculate interestingness measures to predict thecontext.targetvalues (Inherited from DecisionLatticePredictor class)
- predict(context) :noindex:
Predict
context.targetlabels based oncontext.data(Inherited from DecisionLatticePredictor class)
- predict_proba(context) :noindex:
Predict probabilities of
context.targetlabels based oncontext.data
- property algo_params
Dictionary of algorithm specific parameters
- average_concepts_class_probabilities(concepts_i)
Average predictions of concepts with indexes
concepts_ito get a final probability prediction
- average_concepts_predictions(concepts_i)
Average label predictions of concepts with indexes
concepts_ito get a final prediction
- calc_concept_prediction_metrics(c_i, Y)
Calculate the target prediction for concept
c_ibased on ground truth targetsY
- 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.targetpropertyuse_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
contextand calculate interestingness measures to predict thecontext.targetvalues
- predict(context) :noindex:
Predict
context.targetvariables based oncontext.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.targetpropertyuse_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
contextand calculate interestingness measures to predict thecontext.targetvalues (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_ito get a final prediction
- calc_concept_prediction_metrics(c_i, Y)
Calculate the target prediction for concept
`c_ibased on ground truth targetsY
- 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.targetpropertyuse_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
dtmodel fitted oncontextdata
- classmethod from_gradient_boosting(gb, context: MVContext)
Construct the DecisionLattice from the sklearn gradient boosting
gbmodel fitted oncontextdata
- classmethod from_random_forest(rf, context: MVContext)
Construct the DecisionLattice from the sklearn Random Forest
rfmodel fitted oncontextdata
- classmethod from_xgboost(xgb, context: MVContext)
Construct the DecisionLattice from the xgboost
xgbmodel fitted oncontextdata
- 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.