### Install Caspailleur from PyPI Source: https://github.com/smartfca/caspailleur/blob/main/README.md Install the stable version of the Caspailleur package using pip. ```console pip install caspailleur ``` -------------------------------- ### Install Caspailleur from GitHub Source: https://github.com/smartfca/caspailleur/blob/main/README.md Install the latest version of the Caspailleur package directly from its GitHub repository. ```console pip install caspailleur@git+https://github.com/smartFCA/caspailleur ``` -------------------------------- ### Mine All Concepts Source: https://github.com/smartfca/caspailleur/blob/main/README.md Find all concepts in the dataframe and print their extent and intent. This is a basic usage example. ```python concepts_df = csp.mine_concepts(df) print(concepts_df[['extent', 'intent']].map(', '.join)) ``` -------------------------------- ### GET /io/from_fca_repo Source: https://context7.com/smartfca/caspailleur/llms.txt Downloads a formal context from the FCA repository and returns it as a Pandas DataFrame with associated metadata. ```APIDOC ## GET /io/from_fca_repo ### Description Downloads a formal context from the FCA repository and returns it as a Pandas DataFrame with associated metadata. ### Parameters #### Query Parameters - **dataset_name** (string) - Required - The name of the dataset to download from the FCA repository. ### Response #### Success Response (200) - **df** (Pandas DataFrame) - The binary dataset. - **meta** (dict) - Metadata associated with the dataset (title, source, size, etc.). ``` -------------------------------- ### Read and Write CXT Files Source: https://context7.com/smartfca/caspailleur/llms.txt Save and load formal contexts in Burmeister (.cxt) format for interoperability with other FCA tools. You can also get the CXT string directly. ```python import caspailleur as csp # Load sample data df, _ = csp.io.from_fca_repo('famous_animals_en') # Write to CXT file with open('context.cxt', 'w') as f: csp.io.write_cxt(df, f) # Read from CXT file with open('context.cxt', 'r') as f: df_loaded = csp.io.read_cxt(f) # Verify data integrity assert (df == df_loaded).all(None) print("Context successfully saved and loaded!") # Get CXT string without writing to file cxt_string = csp.io.write_cxt(df) print("CXT format preview:") print(cxt_string[:200]) ``` -------------------------------- ### Perform Basic FCA Operations Source: https://context7.com/smartfca/caspailleur/llms.txt Demonstrates calculating extensions, intentions, closures, and powersets for attribute sets in a formal context. ```python # Prepare data df, _ = csp.io.from_fca_repo('famous_animals_en') bitarrays = csp.io.to_bitarrays(df) attr_extents = csp.io.transpose_context(bitarrays) _, objects, attributes = csp.io.to_named_bitarrays(df) # Extension: given attributes, find objects that have ALL of them description = {0, 5} # {'cartoon', 'mammal'} ext = extension(description, attr_extents) ext_names = [objects[i] for i in ext.search(True)] print(f"Objects with cartoon AND mammal: {ext_names}") # Output: ['Garfield', 'Snoopy'] # Intention: given objects (as bitarray), find attributes they ALL share obj_bitarray = ext # Use the extent we just computed intent = intention(obj_bitarray, attr_extents) intent_names = [attributes[i] for i in intent.search(True)] print(f"Attributes shared by those objects: {intent_names}") # Closure: compute intent of the extent of a description closed = closure({0}, attr_extents) # Closure of {'cartoon'} closed_names = [attributes[i] for i in closed.search(True)] print(f"Closure of {{'cartoon'}}: {set(closed_names)}") # Powerset: iterate all subsets for subset in list(powerset({0, 1, 2}))[:5]: print(f" Subset: {subset}") ``` -------------------------------- ### Compute proper premises and pseudo-intents Source: https://context7.com/smartfca/caspailleur/llms.txt Calculate proper premises for the Canonical Direct basis and pseudo-intents for the Canonical basis using LCM-based intent mining. ```python import caspailleur as csp from caspailleur.mine_equivalence_classes import list_intents_via_LCM, list_keys from caspailleur.implication_bases import iter_proper_premises_via_keys, list_pseudo_intents_via_keys # Prepare data df, _ = csp.io.from_fca_repo('famous_animals_en') bitarrays = csp.io.to_bitarrays(df) _, _, attributes = csp.io.to_named_bitarrays(df) # Compute intents and keys intents = list_intents_via_LCM(bitarrays, min_supp=1) keys = list_keys(intents) # Get proper premises (for Canonical Direct basis) proper_premises = list(iter_proper_premises_via_keys(intents, keys)) print(f"Proper premises: {len(proper_premises)}") for pp, intent_idx in proper_premises[:5]: pp_attrs = [attributes[i] for i in pp.search(True)] intent_attrs = [attributes[i] for i in intents[intent_idx].search(True)] print(f" {set(pp_attrs)} -> {set(intent_attrs)}") # Get pseudo-intents (for Canonical basis) pseudo_intents = list_pseudo_intents_via_keys(proper_premises, intents) print(f"\nPseudo-intents: {len(pseudo_intents)}") ``` -------------------------------- ### Load Data from FCA Repository Source: https://context7.com/smartfca/caspailleur/llms.txt Downloads a formal context from the FCA repository and returns it as a Pandas DataFrame with associated metadata. ```python import caspailleur as csp # Load a dataset from the FCA repository df, meta = csp.io.from_fca_repo('famous_animals_en') print("Metadata:", meta) # Output: {'title': 'Famous Animals', 'source': '...', 'size': {'objects': 5, 'attributes': 6}, ...} print("\nDataset:") print(df.replace({True: 'X', False: ''})) # Output: # cartoon real tortoise dog cat mammal # Garfield X X X # Snoopy X X X # Socks X X X # Greyfriar's Bobby X X X # Harriet X X ``` -------------------------------- ### Compute Keys and Passkeys Source: https://context7.com/smartfca/caspailleur/llms.txt Compute minimal and minimum generators for intents. Keys are minimal attribute sets with unique closures, while passkeys are the smallest such sets. Requires intents computed via LCM. ```python import caspailleur as csp from caspailleur.mine_equivalence_classes import list_intents_via_LCM, list_keys, list_passkeys # Prepare data df, _ = csp.io.from_fca_repo('famous_animals_en') bitarrays = csp.io.to_bitarrays(df) # Compute intents and their keys intents = list_intents_via_LCM(bitarrays, min_supp=1) keys_dict = list_keys(intents) passkeys_dict = list_passkeys(intents) print(f"Total keys: {len(keys_dict)}") print(f"Total passkeys: {len(passkeys_dict)}") # Show sample keys _, _, attributes = csp.io.to_named_bitarrays(df) for key, intent_idx in list(keys_dict.items())[:5]: key_attrs = [attributes[i] for i in key.search(True)] print(f"Key {set(key_attrs) or '{}'} -> Intent #{intent_idx}") ``` -------------------------------- ### Save and Load Formal Context Source: https://github.com/smartfca/caspailleur/blob/main/README.md Persists a formal context to a .cxt file and restores it, verifying integrity with an assertion. ```python with open('context.cxt', 'w') as file: csp.io.write_cxt(df, file) with open('context.cxt', 'r') as file: df_loaded = csp.io.read_cxt(file) assert (df == df_loaded).all(None) ``` -------------------------------- ### Load and Print Famous Animals Dataset Source: https://github.com/smartfca/caspailleur/blob/main/README.md Load the 'famous_animals_en' dataset from the FCA repository using caspailleur. This snippet also prints the metadata and a formatted version of the dataset. ```python import caspailleur as csp df, meta = csp.io.from_fca_repo('famous_animals_en') print(meta) print(df.replace({True: 'X', False: ''})) ``` -------------------------------- ### Mine Formal Concepts Source: https://context7.com/smartfca/caspailleur/llms.txt Discovers all formal concepts in the data, optionally applying support and stability constraints. ```python import caspailleur as csp # Load sample data df, _ = csp.io.from_fca_repo('famous_animals_en') # Mine all concepts with default settings concepts_df = csp.mine_concepts(df) print("Total concepts found:", len(concepts_df)) print(concepts_df[['extent', 'intent']].head()) # Output shows concept pairs with their extents and intents # Mine concepts with support and stability constraints concepts_df = csp.mine_concepts( df, min_support=2, # At least 2 objects in extent min_delta_stability=1, # Minimum delta-stability to_compute=['intent', 'keys', 'support', 'delta_stability', 'sub_concepts'] ) print("\nFiltered concepts:") print(concepts_df) # Output: # concept_id intent keys support delta_stability sub_concepts # 0 0 set() [set()] 5 1 {1, 2} # 1 1 {'mammal'} [{'mammal'}] 4 2 set() # 2 2 {'real'} [{'real'}] 3 1 set() ``` -------------------------------- ### Mine all data descriptions Source: https://github.com/smartfca/caspailleur/blob/main/README.md Outputs all possible descriptions for the dataset. Note that the number of descriptions grows exponentially with the number of attributes. ```python descriptions_df = csp.mine_descriptions(df) print('__n. attributes:__', df.shape[1]) print('__n. descriptions:__', len(descriptions_df)) print('__columns:__', ', '.join(descriptions_df.columns)) print(descriptions_df[['description', 'support', 'is_key']].head(3)) ``` -------------------------------- ### Mine Stable Concepts with Filters Source: https://github.com/smartfca/caspailleur/blob/main/README.md Mine concepts with specific filters for minimum support, delta stability, and to compute additional properties like keys and sub-concepts. Use this to find more interesting or stable concepts. ```python concepts_df = csp.mine_concepts( df, min_support=3, min_delta_stability=1, to_compute=['intent', 'keys', 'support', 'delta_stability', 'sub_concepts'] ) print(concepts_df) ``` -------------------------------- ### Mine concepts for lattice visualization Source: https://github.com/smartfca/caspailleur/blob/main/README.md Extracts concepts from the dataset based on a minimum support threshold, which can be used to generate mermaid diagrams. ```python concepts_df = csp.mine_concepts(df, min_support=2) ``` -------------------------------- ### POST /mine_descriptions Source: https://context7.com/smartfca/caspailleur/llms.txt Computes all possible attribute descriptions and their characteristics for a given binary dataset. ```APIDOC ## POST /mine_descriptions ### Description Computes all possible attribute descriptions and their characteristics. Useful for analyzing every possible combination of attributes. ### Parameters #### Request Body - **df** (Pandas DataFrame) - Required - The binary dataset. - **min_support** (int) - Optional - Minimum support threshold. ### Response #### Success Response (200) - **descriptions_df** (Pandas DataFrame) - A DataFrame containing descriptions and metrics such as support, delta_stability, and flags for closed/key/proper premise status. ``` -------------------------------- ### Generate Mermaid diagram code Source: https://github.com/smartfca/caspailleur/blob/main/README.md Constructs node labels with intent and extent information and generates a Mermaid diagram string. ```python new_intent_labels = ('' + concepts_df['new_intent'].map(sorted).map(', '.join) + '').replace('', '') old_intent_labels = (concepts_df['intent'] - concepts_df['new_intent']).map(sorted).map(', '.join) intent_labels = (new_intent_labels + ';' + old_intent_labels).map(lambda l: ', '.join(l.strip(';').split(';'))) extent_labels = concepts_df['extent'].map(sorted).map(', '.join) node_labels = intent_labels + '

' + extent_labels node_labels = [l.replace(' ', ' ') for l in node_labels] # replace space with non-breakable space for better Mermaid visualisation diagram_code = csp.io.to_mermaid_diagram(node_labels, concepts_df['previous_concepts']) print(diagram_code) ``` -------------------------------- ### Generate Mermaid diagrams Source: https://context7.com/smartfca/caspailleur/llms.txt Convert concept lattice data into Mermaid flowchart syntax for visualization. ```python import caspailleur as csp # Load and mine concepts df, _ = csp.io.from_fca_repo('famous_animals_en') concepts_df = csp.mine_concepts(df, min_support=2) # Prepare node labels new_intent_labels = ('' + concepts_df['new_intent'].map(sorted).map(', '.join) + '').replace('', '') extent_labels = concepts_df['extent'].map(sorted).map(', '.join) node_labels = new_intent_labels + '

' + extent_labels node_labels = [l.replace(' ', ' ') for l in node_labels] # Generate Mermaid diagram code diagram_code = csp.io.to_mermaid_diagram(node_labels, concepts_df['previous_concepts']) print("Mermaid diagram code (paste into https://mermaid.live/):") print(diagram_code) # Output: # flowchart TD # A["

Garfield, ..."]; # B["mammal

..."]; # ... ``` -------------------------------- ### Sort intents and compute lattice order Source: https://context7.com/smartfca/caspailleur/llms.txt Organize intents topologically and determine parent-child relationships to represent the concept lattice structure. ```python import caspailleur as csp from caspailleur.order import topological_sorting, sort_intents_inclusion, inverse_order # Prepare data df, _ = csp.io.from_fca_repo('famous_animals_en') bitarrays = csp.io.to_bitarrays(df) from caspailleur.mine_equivalence_classes import list_intents_via_LCM intents = list_intents_via_LCM(bitarrays, min_supp=1) # Topologically sort intents (smallest first) sorted_intents, idx_map = topological_sorting(intents) print(f"Sorted {len(sorted_intents)} intents from smallest to largest") # Compute parent-child relationships parents, trans_parents = sort_intents_inclusion(sorted_intents, return_transitive_order=True) children = inverse_order(parents) # Show lattice structure _, _, attributes = csp.io.to_named_bitarrays(df) for i, intent in enumerate(sorted_intents[:5]): attrs = [attributes[j] for j in intent.search(True)] parent_indices = list(parents[i].search(True)) print(f"Intent {i}: {set(attrs) or '∅'} <- parents: {parent_indices}") ``` -------------------------------- ### Mine partial implications with custom parameters Source: https://github.com/smartfca/caspailleur/blob/main/README.md Configures the mining process with specific basis types, unit-base transformations, and support thresholds to optimize performance on large datasets. ```python implications_df = csp.mine_implications( df, basis_name='Canonical', unit_base=True, to_compute=['premise', 'conclusion', 'extent'], min_support=2, ) print(implications_df) ``` -------------------------------- ### Convert Formal Context to Dictionary Source: https://github.com/smartfca/caspailleur/blob/main/README.md Represents a formal context as a dictionary mapping object names to sets of their attributes. ```python print(csp.io.to_dictionary(df)) ``` -------------------------------- ### Compute Intents via LCM Algorithm Source: https://context7.com/smartfca/caspailleur/llms.txt Use the `list_intents_via_LCM` function for a low-level computation of closed itemsets (intents) using the efficient LCM algorithm. Requires data in bitarray format. ```python import caspailleur as csp from caspailleur.mine_equivalence_classes import list_intents_via_LCM # Prepare data in bitarray format df, _ = csp.io.from_fca_repo('famous_animals_en') bitarrays, objects, attributes = csp.io.to_named_bitarrays(df) # Compute intents with minimum support threshold intents = list_intents_via_LCM(bitarrays, min_supp=2) print(f"Found {len(intents)} intents with support >= 2") # Convert intents back to readable format for intent in intents: attrs = [attributes[i] for i in intent.search(True)] print(f" Intent: {set(attrs) if attrs else '∅ (top concept)'}") ``` -------------------------------- ### Mermaid flowchart diagram Source: https://github.com/smartfca/caspailleur/blob/main/README.md A visual representation of the concept hierarchy generated by the library. ```mermaid flowchart TD A["

Garfield, Greyfriar's Bobby, Harriet, Snoopy, Socks"]; B["mammal

Garfield, Greyfriar's Bobby, Snoopy, Socks"]; C["real

Greyfriar's Bobby, Harriet, Socks"]; D["cartoon, mammal

Garfield, Snoopy"]; E["mammal, real

Greyfriar's Bobby, Socks"]; F["dog, mammal

Greyfriar's Bobby, Snoopy"]; G["cat, mammal

Garfield, Socks"]; A --- B; A --- C; B --- D; B --- E; B --- F; B --- G; C --- E; ``` -------------------------------- ### POST /mine_concepts Source: https://context7.com/smartfca/caspailleur/llms.txt Discovers all formal concepts in the data, where a concept is a pair of an extent and an intent that are maximally associated. ```APIDOC ## POST /mine_concepts ### Description Discovers all formal concepts in the data. A concept is a pair of an extent (set of objects) and an intent (set of attributes) that are maximally associated with each other. ### Parameters #### Request Body - **df** (Pandas DataFrame) - Required - The binary dataset. - **min_support** (int) - Optional - Minimum number of objects in the extent. - **min_delta_stability** (int) - Optional - Minimum delta-stability value. - **to_compute** (list) - Optional - List of metrics to compute (e.g., 'intent', 'keys', 'support', 'delta_stability', 'sub_concepts'). ### Response #### Success Response (200) - **concepts_df** (Pandas DataFrame) - A DataFrame containing the discovered concepts and their associated metrics. ``` -------------------------------- ### Test Attribute Set Properties Source: https://context7.com/smartfca/caspailleur/llms.txt Evaluates whether specific attribute sets are closed, keys, or proper premises within a formal context. ```python import caspailleur as csp from caspailleur.definitions import is_closed, is_key, is_passkey, is_proper_premise # Prepare data df, _ = csp.io.from_fca_repo('famous_animals_en') bitarrays = csp.io.to_bitarrays(df) attr_extents = csp.io.transpose_context(bitarrays) _, _, attributes = csp.io.to_named_bitarrays(df) # Test various attribute sets test_sets = [ frozenset({0}), # {'cartoon'} frozenset({5}), # {'mammal'} frozenset({0, 5}), # {'cartoon', 'mammal'} frozenset({0, 4, 5}), # {'cartoon', 'cat', 'mammal'} ] for attr_set in test_sets: attr_names = {attributes[i] for i in attr_set} closed = is_closed(attr_set, attr_extents) key = is_key(attr_set, attr_extents) proper = is_proper_premise(attr_set, attr_extents) print(f"{attr_names}:") print(f" is_closed={closed}, is_key={key}, is_proper_premise={proper}") ``` -------------------------------- ### Compute delta-stability index Source: https://context7.com/smartfca/caspailleur/llms.txt Measure the stability of specific attribute descriptions within a formal context. ```python import caspailleur as csp from caspailleur.indices import delta_stability_by_description, support_by_description # Prepare data df, _ = csp.io.from_fca_repo('famous_animals_en') bitarrays = csp.io.to_bitarrays(df) attr_extents = csp.io.transpose_context(bitarrays) _, objects, attributes = csp.io.to_named_bitarrays(df) # Compute delta-stability for specific descriptions descriptions = [ {0}, # {'cartoon'} {1}, # {'real'} {0, 4, 5}, # {'cartoon', 'cat', 'mammal'} ] for desc_indices in descriptions: delta = delta_stability_by_description(desc_indices, attr_extents) support = support_by_description(desc_indices, attr_extents) desc_attrs = [attributes[i] for i in desc_indices] print(f"Description {set(desc_attrs)}: support={support}, delta_stability={delta}") ``` -------------------------------- ### Convert to BoolContextType Source: https://github.com/smartfca/caspailleur/blob/main/README.md Converts data into a list of object descriptions as lists of boolean values. ```python print(*csp.io.to_bools(df), sep='\n') ``` -------------------------------- ### Mine Attribute Descriptions Source: https://context7.com/smartfca/caspailleur/llms.txt Computes all possible attribute descriptions and their characteristics, noting that this operation is exponential relative to the number of attributes. ```python import caspailleur as csp # Load sample data df, _ = csp.io.from_fca_repo('famous_animals_en') # Mine all descriptions (note: exponential - 2^n_attributes) descriptions_df = csp.mine_descriptions(df, min_support=2) print("Columns available:", list(descriptions_df.columns)) # ['description', 'extent', 'intent', 'support', 'delta_stability', # 'is_closed', 'is_key', 'is_passkey', 'is_proper_premise', 'is_pseudo_intent'] print("\nSample descriptions:") print(descriptions_df[['description', 'support', 'is_key', 'is_closed']].head(10)) ``` -------------------------------- ### Base functions for derivation operators Source: https://context7.com/smartfca/caspailleur/llms.txt Core FCA operations for computing extensions, intentions, and closures. ```python import caspailleur as csp from caspailleur.base_functions import extension, intention, closure, powerset ``` -------------------------------- ### Convert Between Data Formats Source: https://context7.com/smartfca/caspailleur/llms.txt Caspailleur supports multiple data formats for formal contexts. Convert between DataFrame, itemsets, bitarrays, dictionaries, and boolean lists as needed. ```python import caspailleur as csp import pandas as pd # Create sample binary DataFrame df = pd.DataFrame({ 'has_wings': [True, True, False, False], 'can_fly': [True, False, False, False], 'has_feathers': [True, True, False, False], 'mammal': [False, False, True, True] }, index=['eagle', 'penguin', 'dog', 'cat']) # Convert to different formats itemsets = csp.io.to_itemsets(df) print("Itemsets format:", itemsets) # [{0, 1, 2}, {0, 2}, {3}, {3}] - indices of True attributes per object bitarrays = csp.io.to_bitarrays(df) print("Bitarrays format:", bitarrays) # [bitarray('1110'), bitarray('1010'), bitarray('0001'), bitarray('0001')] dictionary = csp.io.to_dictionary(df) print("Dictionary format:", dictionary) # {'eagle': {'has_wings', 'can_fly', 'has_feathers'}, 'penguin': {...}, ...} bools = csp.io.to_bools(df) print("Bools format:", bools) # [[True, True, True, False], [True, False, True, False], ...] # Named versions include object and attribute names named_bitarrays = csp.io.to_named_bitarrays(df) bitarrays, objects, attributes = named_bitarrays print(f"Objects: {objects}, Attributes: {attributes}") # Transpose context (swap objects and attributes) transposed = csp.io.transpose_context(df) print("Transposed context shape:", transposed.shape) ``` -------------------------------- ### Compute Stable Extents via gSofia Source: https://context7.com/smartfca/caspailleur/llms.txt Find delta-stable extents using the gSofia algorithm. Stable extents are robust to small perturbations in the data. Requires data in bitarray format and transposed attribute extents. ```python import caspailleur as csp from caspailleur.mine_equivalence_classes import list_stable_extents_via_gsofia # Prepare data df, _ = csp.io.from_fca_repo('famous_animals_en') bitarrays = csp.io.to_bitarrays(df) attr_extents = csp.io.transpose_context(bitarrays) ``` -------------------------------- ### Find most stable extents Source: https://context7.com/smartfca/caspailleur/llms.txt Identify stable extents using the G-Sofia algorithm with specified support and stability constraints. ```python stable_extents = list_stable_extents_via_gsofia( attr_extents, n_objects=len(bitarrays), min_delta_stability=1, n_stable_extents=10, # Maximum number of extents to return min_supp=2 # Minimum support ) print(f"Found {len(stable_extents)} stable extents") _, objects, _ = csp.io.to_named_bitarrays(df) for extent in stable_extents: objs = [objects[i] for i in extent.search(True)] print(f" Stable extent: {objs}") ``` -------------------------------- ### Convert to PandasContextType Source: https://github.com/smartfca/caspailleur/blob/main/README.md Converts data into a binary Pandas dataframe. ```python print(csp.io.to_pandas(df)) ``` -------------------------------- ### Convert to NamedBitarrayContextType Source: https://github.com/smartfca/caspailleur/blob/main/README.md Converts data into a triplet containing bitarrays, object names, and attribute names. ```python print(*csp.io.to_named_bitarrays(df), sep='\n') ``` -------------------------------- ### Iterate Descriptions Efficiently Source: https://context7.com/smartfca/caspailleur/llms.txt Use this iterator for memory-efficiently processing descriptions when the full DataFrame is too large. It allows processing one description at a time. ```python import caspailleur as csp # Load sample data df, _ = csp.io.from_fca_repo('famous_animals_en') # Iterate through descriptions one at a time for i, desc in enumerate(csp.iter_descriptions(df, to_compute=['description', 'support', 'is_key'])): if desc['support'] >= 3 and desc['is_key']: print(f"Key description with high support: {desc['description']} (support={desc['support']})") if i > 20: # Early stopping for demo break ``` -------------------------------- ### Compute Linearity and Distributivity Indices Source: https://context7.com/smartfca/caspailleur/llms.txt Calculates complexity measures for concept lattices to determine structural properties like chain-like or distributive characteristics. ```python import caspailleur as csp from caspailleur.indices import linearity_index, distributivity_index from caspailleur.order import sort_intents_inclusion from caspailleur.mine_equivalence_classes import list_intents_via_LCM # Prepare data and compute lattice structure df, _ = csp.io.from_fca_repo('famous_animals_en') bitarrays = csp.io.to_bitarrays(df) intents = list_intents_via_LCM(bitarrays) parents, trans_parents = sort_intents_inclusion(intents, return_transitive_order=True) # Compute indices n_trans_parents = sum(p.count() for p in trans_parents) n_elements = len(intents) lin_idx = linearity_index(n_trans_parents, n_elements) print(f"Linearity index: {lin_idx:.3f}") # Higher values indicate more chain-like structure dist_idx = distributivity_index(intents, parents, n_trans_parents) print(f"Distributivity index: {dist_idx:.3f}") # Higher values indicate more distributive lattice ``` -------------------------------- ### Convert to BitarrayContextType Source: https://github.com/smartfca/caspailleur/blob/main/README.md Converts data into a list of bitarrays representing active attributes. ```python print(*csp.io.to_bitarrays(df), sep='\n') ``` -------------------------------- ### Cite Caspailleur Source: https://github.com/smartfca/caspailleur/blob/main/README.md BibTeX citation entry for the Caspailleur package. ```bibtex @misc{caspailleur, title={caspailleur}, author={Dudyrev, Egor}, year={2023}, howpublished={\url{https://www.smartfca.org/software}}, } ``` -------------------------------- ### Convert to ItemsetContextType Source: https://github.com/smartfca/caspailleur/blob/main/README.md Converts data into a list of sets of indices representing True columns. ```python print(*csp.io.to_itemsets(df), sep='\n') ``` -------------------------------- ### Convert Formal Context to Named Boolean Triplet Source: https://github.com/smartfca/caspailleur/blob/main/README.md Extracts a triplet of boolean values, object names, and attribute names from a formal context. ```python print(*csp.io.to_named_bools(df), sep='\n') ``` -------------------------------- ### Convert to NamedItemsetContextType Source: https://github.com/smartfca/caspailleur/blob/main/README.md Converts data into a triplet containing itemsets, object names, and attribute names. ```python print(*csp.io.to_named_itemsets(df), sep='\n') ``` -------------------------------- ### Mine Implication Bases Source: https://context7.com/smartfca/caspailleur/llms.txt Extracts implication bases from the data, supporting different basis types and unit conclusions. ```python import caspailleur as csp # Load sample data df, _ = csp.io.from_fca_repo('famous_animals_en') # Mine implications using default Proper Premise (Canonical Direct) basis implications_df = csp.mine_implications(df) print("Implications found:") print(implications_df[['premise', 'conclusion', 'support']]) # Output: # implication_id premise conclusion support # 0 0 {'cartoon'} {'mammal'} 2 # 1 1 {'tortoise'} {'real'} 1 # 2 2 {'dog'} {'mammal'} 2 # 3 3 {'cat'} {'mammal'} 2 # Mine Canonical (Duquenne-Guigues) basis with unit conclusions implications_df = csp.mine_implications( df, basis_name='Canonical', # Also accepts 'Pseudo-Intent', 'Duquenne-Guigues' unit_base=True, # Each implication has single-attribute conclusion to_compute=['premise', 'conclusion', 'extent'], min_support=2 ) print("\nUnit basis implications:") print(implications_df) ``` -------------------------------- ### Mine implications from a dataset Source: https://github.com/smartfca/caspailleur/blob/main/README.md Extracts relationships between attributes as an implication basis. The resulting DataFrame contains premises, conclusions, and support counts. ```python implications_df = csp.mine_implications(df) print(implications_df[['premise', 'conclusion', 'support']]) ``` -------------------------------- ### POST /mine_implications Source: https://context7.com/smartfca/caspailleur/llms.txt Extracts implication bases from the data, representing dependency rules between attributes. ```APIDOC ## POST /mine_implications ### Description Extracts implication bases from the data. An implication A → B means whenever all attributes in A appear in a description, all attributes in B also appear. ### Parameters #### Request Body - **df** (Pandas DataFrame) - Required - The binary dataset. - **basis_name** (string) - Optional - The type of basis to mine (e.g., 'Proper Premise', 'Canonical', 'Pseudo-Intent', 'Duquenne-Guigues'). - **unit_base** (boolean) - Optional - If True, each implication has a single-attribute conclusion. - **to_compute** (list) - Optional - List of metrics to compute. - **min_support** (int) - Optional - Minimum support threshold. ### Response #### Success Response (200) - **implications_df** (Pandas DataFrame) - A DataFrame containing the extracted implications. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.