fcapy.algorithms.concept_construction
This module contains functions that take a FormalContext (or MVContext) and return a set of formal (or pattern) concepts. Some of them return a ConceptLattice instead of just a set of concepts.
Functions
|
Return a list of concepts generated by CloseByOne (CbO) algorithm |
|
Get Concept Lattice from Formal Context using Lindig algorithm (https://www.researchgate.net/publication/2812391_Fast_Concept_Analysis) |
|
Return a set of extents of nodes from sklearn DecisionTree (or RandomForest) |
|
Fit a RandomForest model and return a set of pattern concepts used by this model |
|
Return a lattice of the most interesting concepts generated by SOFIA algorithm. |
|
Return a lattice of the most interesting concepts generated by SOFIA algorithm. |
- fcapy.algorithms.concept_construction.close_by_one(context: MVContext, output_as_concepts=True, iterate_extents=None, initial_combinations=None, iter_elements_to_check=None)
Return a list of concepts generated by CloseByOne (CbO) algorithm
- Parameters
context (FormalContext or MVContext) – A context to build a set of concepts on
output_as_concepts (bool) – A flag whether to return a list of concepts as a list of FormalConcept/PatternConcept objects (if set True) or as a dictionary with concepts extents and intents
iterate_extents (bool) – A flag whether to run CbO by iterating through subsets of objects (if set True) or of attributes (if set False) By default it sets to True if the set of objects is smaller than the set of attributes
initial_combinations (list of int) – A list of subsets of objects/attributes indexes (depends on
iterate_extents) to start CbO algorithm from Default value is empty list []iter_elements_to_check (list of int) – A list of attributes/objects indexes (depends on
iterate_extents) to run CbO algorithm on
- Returns
Either
dataorconceptsdepends onoutput_as_conceptsattributedata (dict) – A dictionary which contains a set of concepts extents and concepts intents
concepts (list of FormalConcept or PatternConcept) – A list of concepts of class FormalConcept (if given context is of type FormalContext) or PatternConcept (if given context is of type MVContext)
- fcapy.algorithms.concept_construction.lindig_algorithm(context: FormalContext, iterate_extents=None)
Get Concept Lattice from Formal Context using Lindig algorithm (https://www.researchgate.net/publication/2812391_Fast_Concept_Analysis)
- Parameters
context (FormalContext) – A context to build lattice on
iterate_extents (bool) – A flag whether to run Lindig by iterating through subsets of objects (if set True) or of attributes (if set False) By default it sets to True if the set of objects is smaller than the set of attributes and False otherwise
- Returns
lattice – A ConceptLattice which contains a set of Formal Concepts and relations between them
- Return type
ConceptLattice
- fcapy.algorithms.concept_construction.parse_decision_tree_to_extents(tree, X, n_jobs=1)
Return a set of extents of nodes from sklearn DecisionTree (or RandomForest)
- Parameters
tree (DecisionTreeRegressor or DecisionTreeClassifier or RandomForestRegressor or RandomForestClassifier) – sklearn DecisionTree or RandomForest to retrieve a set of extents from
X (numpy.ndarray) – An input data for
treemodel. The same format it is used fortree.predict(X)functionn_jobs (int) – A number of parallel jobs to run. WARNING: A number of jobs works slower than a single one.
- Returns
exts – A list of objects indexes from
Xdescribed by nodes of decision tree(s) fromtree- Return type
list of int
- fcapy.algorithms.concept_construction.random_forest_concepts(context: MVContext, rf_params=None, rf_class=None)
Fit a RandomForest model and return a set of pattern concepts used by this model
- Parameters
context (MVContext) – A context to fit a RandomForest on. Training features data for the Forest are kept in context.data Target values are kept in
context.targetrf_params (dict) – A dict of parameters to initialize RandomForest model with
rf_class (type RandomForestRegressor or RandomForestClassifier) – A type of RandomForest model to fit. By default this value is set to RandomForestClassifier if
context.targetvalue has only 2 distinct values
- Returns
concepts – A list of PatternConcepts retrieved from context by RandomForest
- Return type
list of PatternConcept
- fcapy.algorithms.concept_construction.sofia_binary(context: MVContext, L_max=100, iterate_attributes=True, measure='LStab', projection_sorting=None, proj_to_start=None, use_tqdm=False)
Return a lattice of the most interesting concepts generated by SOFIA algorithm. Optimized for FormalContext
WARNING: The author of the algorithm (A. Buzmakov) said this function is not an accurate implementation of the original Sofia algorithm. Thus the function may work not as efficient as expected.
- Parameters
context (FormalContext or MVContext) – A context to build a list of concepts on
L_max (int) – Maximum size of returned lattice. That is the maximum number of most interesting concepts
iterate_attributes (bool) – A flag whether to iterate a set of attributes as a chain of projections (if set to True) or a set of objects o/w
measure (string) – The name of a concept interesting measure to maximize
projection_sorting (str of {‘ascending’, ‘descending’, ‘random’, None}) – A way to sort a chain of projections by their support. E.g. if
iterate_attributesis set to True, ‘Ascending’ sorting start running projections from an attribute shared by the least amount of objects to an attributes shared by the most amount of objectsproj_to_start (int) – A number of projection (a set of attributes/objects) to construct a basic ConceptLattice on
use_tqdm (bool) – A flag whether to visualize the progress of the algorithm with tqdm bar or not
- Returns
lattice – A ConceptLattice which contains a set of Formal (or Pattern) concepts with high values of given interesting measure
- Return type
ConceptLattice
- fcapy.algorithms.concept_construction.sofia_general(context: MVContext, L_max=100, measure='LStab', proj_to_start=None, use_tqdm=False)
Return a lattice of the most interesting concepts generated by SOFIA algorithm. Can work with any MVContext
WARNING: The author of the algorithm (A. Buzmakov) said this is not an accurate implementation of the original Sofia algorithm. Thus the function may work not as efficient as expected. Moreover it represents the simplest way construct a lattice over MVContext. Therefore it is very inefficient.
- Parameters
context (FormalContext or MVContext) – A context to build a list of concepts on
L_max (int) – Maximum size of returned lattice. That is the maximum number of most interesting concepts
measure (string) – The name of a concept interesting measure to maximize
proj_to_start (int) – A number of projection (a set of attributes/objects) to construct a basic ConceptLattice on
use_tqdm (bool) – A flag whether to visualize the progress of the algorithm with tqdm bar or not
- Returns
lattice – A ConceptLattice which contains a set of Formal (or Pattern) concepts with high values of given interesting measure
- Return type
ConceptLattice