### Clone and Install Repository Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/contributing.md Clone the forked repository and install the project in editable mode. This setup is necessary for local development and testing. ```bash git clone git@github.com:YourLogin/pysubgroup.git cd pysubgroup pip install -U pip setuptools -e . ``` -------------------------------- ### Install and Configure Pre-commit Hooks Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/contributing.md Install pre-commit and set up the git hooks for the project. These hooks automatically check code quality before commits. ```bash pip install pre-commit pre-commit install ``` -------------------------------- ### setup Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/pysubgroup.md Prepares the algorithm by setting up the task, depth, constraints, and quality function. This is an initialization step for subgroup discovery. ```APIDOC ## setup(task) ### Description Prepares the algorithm by setting up the task, depth, constraints, and quality function. ### Parameters * **task** (*SubgroupDiscoveryTask*) – The task to execute. ``` -------------------------------- ### Example Badge URLs Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/readme.md These are examples of badge URLs that can be added to a README file to display project status and metrics. Ensure URLs are updated to reflect the correct project. ```markdown [![Twitter](https://img.shields.io/twitter/url/http/shields.io.svg?style=social&label=Twitter)](https://twitter.com/pysubgroup) ``` -------------------------------- ### Install pysubgroup via pip Source: https://github.com/flemmerich/pysubgroup/blob/master/README.md Install the pysubgroup package using pip. This is the recommended installation method. ```bash pip install pysubgroup ``` -------------------------------- ### Disjunction Example Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/sections/components/selectors.md Shows how to use Disjunction to find instances that satisfy at least one of the specified conditions. This is useful for broader search criteria. ```python from pysubgroup.datasets import load_allonesian_adults data = load_allonesian_adults() selector_alex = EqualitySelector("firstname", "Alex") selector_age_interval = IntervalSelector("age", 18, 40) disjunction = Disjunction([selector_alex, selector_age_interval]) print(disjunction.covers(data).to_numpy()) ``` -------------------------------- ### Run unit tests with tox Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/contributing.md Verify that your changes do not break any unit tests by running the tox command. Ensure tox is installed. ```shell tox ``` -------------------------------- ### Example Model Prediction Results Source: https://github.com/flemmerich/pysubgroup/blob/master/examples/model_predictions_target.ipynb This is an example output showing a list of tuples, where each tuple contains a quality score, a subgroup representation, and an empty dictionary. This format is typical for results from subgroup discovery algorithms. ```python [(16.11950218654796, (checking_status_b'no checking'==False), {}), (10.323861776658976, (checking_status_b'0<=X<200'==True), {}), (8.444831364941551, (age<26.0), {}), (7.582661649978409, (checking_status_b'<0'==True), {}), (3.3928681587637555, (credit_history_b'critical/other existing credit'==False), {}), (3.1271094686412226, (existing_credits==1.0), {}), (3.080708868443441, (employment_b'1<=X<4'==True), {}), (2.823392613602404, (employment_b'unemployed'==True), {}), (2.7609864882592157, (other_parties_b'co applicant'==True), {}), (2.640285148745762, (property_magnitude_b'car'==False), {}), (2.612080399959171, (housing_b'own'==True), {}), (2.555613970650818, (employment_b'4<=X<7'==False), {}), (2.5116631357417605, (job_b'high qualif/self emp/mgmt'==True), {}), (2.4072073218078724, (property_magnitude_b'real estate'==True), {}), (2.3900463909277776, (purpose_b'furniture/equipment'==True), {}), (2.35137085137085, (credit_history_b'delayed previously'==True), {}), (2.3489608625174756, (duration: [12.0:18.0[), {}), (2.2145001438324425, (credit_history_b'existing paid'==True), {}), (2.1344004604387474, (employment_b'>=7'==False), {}), (2.101750538511135, (installment_commitment==2.0), {}), (1.957711454083699, (housing_b'rent'==False), {}), (1.889681159753434, (job_b'skilled'==False), {}), (1.8582519408965679, (purpose_b'business'==True), {}), (1.7805968015587599, (num_dependents==1.0), {}), (1.7430720927885384, (other_parties_b'none'==False), {}), (1.6539509086260782, (residence_since==1.0), {}), (1.3843978954544036, (duration: [18.0:24.0[), {}), (1.3188365635918076, (other_payment_plans_b'bank'==True), {}), (1.2600246748277562, (purpose_b'new car'==False), {}), (1.1539988630897724, (personal_status_b'male div/sep'==True), {}), (1.1522930194805192, (credit_amount: [2762.0:4583.0[), {}), (1.0829335768398278, (purpose_b'radio/tv'==True), {}), (1.0763481926705118, (savings_status_b'>=1000'==False), {}), (1.0760055976064418, (other_payment_plans_b'none'==False), {}), (1.0344818101416355, (residence_since==2.0), {}), (1.0219984841196956, (credit_history_b'all paid'==True), {}), (0.9854651877116379, (credit_history_b'no credits/all paid'==False), {}), (0.8325421831716843, (credit_history_b'all paid'==False), {}), (0.809778599669471, (personal_status_b'male single'==False), {}), (0.7620595566050107, (foreign_worker_b'yes'==False), {}), (0.7620595566050107, (foreign_worker_b'no'==True), {}), (0.738316498316496, (index<240), {}), (0.7381067907592677, (employment_b'<1'==False), {}), (0.7085028413699723, (duration>=30.0), {}), (0.6002019619264808, (savings_status_b'<100'==False), {}), (0.545221499342776, (purpose_b'used car'==False), {}), (0.4906571969419986, (purpose_b'radio/tv'==False), {}), (0.45922460973369866, (property_magnitude_b'life insurance'==True), {}), (0.4165244154743397, (housing_b'for free'==False), {}), (0.40677444642652166, (purpose_b'domestic appliance'==False), {}), (0.3989149795210399, (checking_status_b'>=200'==True), {}), (0.3971382975457217, (index: [634:825[), {}), (0.38923813346754543, (own_telephone_b'yes'==True), {}), (0.38923813346754543, (own_telephone_b'none'==False), {}), (0.3615289256198345, (personal_status_b'male mar/wid'==True), {}), (0.3418551089512683, (purpose_b'education'==False), {}), (0.33754113343274145, (age>=43.0), {}), (0.336064046245444, (credit_amount: [1845.0:2762.0[), {}), (0.335676999190374, (job_b'unskilled resident'==False), {}), (0.3033054315105592, (savings_status_b'no known savings'==True), {}), (0.29734744264038443, (purpose_b'repairs'==False), {}), (0.2929180194805169, (index: [240:440[), {}), (0.25888557074124136, (savings_status_b'<100'==True), {}), (0.2533809382648786, (purpose_b'retraining'==False), {}), (0.24626715006054686, (installment_commitment==1.0), {}), (0.18506024999531434, (savings_status_b'500<=X<1000'==True), {}), (0.1788787344342899, (existing_credits==3.0), {}), (0.17849987767824887, (credit_amount: [1283.0:1845.0[), {}), (0.15185694990580906, (age: [36.0:43.0[), {}), (0.13619965892693153, (job_b'unemp/unskilled non res'==True), {}), (0.09596090777908446, (checking_status_b'<0'==False), {}), (0.09243056726822954, (housing_b'for free'==True), {}), (0.07647388623673317, (purpose_b'other'==False), {}), (0.0701065388073857, (residence_since==3.0), {}), (0.05602420599093432, (job_b'unemp/unskilled non res'==False), {}), (0.02915637046894749, (property_magnitude_b'no known property'==False), {})] ``` -------------------------------- ### Conjunction Example Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/sections/components/selectors.md Demonstrates creating complex queries by combining multiple selectors using Conjunction. This finds instances that satisfy all specified conditions. ```python from pysubgroup.datasets import load_allonesian_adults data = load_allonesian_adults() selector_alex = EqualitySelector("firstname", "Alex") selector_age_interval = IntervalSelector("age", 18, 40) conjunction = Conjunction([selector_alex, selector_age_interval]) print(conjunction.covers(data).to_numpy()) ``` -------------------------------- ### EqualitySelector Example Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/sections/components/selectors.md Demonstrates the usage of EqualitySelector to find instances with a specific attribute value. Useful for binary, string, and categorical data. ```python from pysubgroup.datasets import load_allonesian_adults data = load_allonesian_adults() selector_alex = EqualitySelector("firstname", "Alex") print(selector_alex.covers(data).to_numpy()) selector_age = EqualitySelector("age", 22) print(selector_age.covers(data).to_numpy()) ``` -------------------------------- ### Create and activate a virtual environment for tox Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/contributing.md If facing issues with tox, create a dedicated virtual environment, install tox within it, and then run tox commands. ```shell virtualenv .venv source .venv/bin/activate .venv/bin/pip install tox .venv/bin/tox -e all ``` -------------------------------- ### NegatedSelector Example Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/sections/components/selectors.md Illustrates how to invert an existing selector using NegatedSelector. This is useful for finding instances that do not meet a specific condition. ```python from pysubgroup.datasets import load_allonesian_adults data = load_allonesian_adults() selector_alex = EqualitySelector("firstname", "Alex") negated_selector = NegatedSelector(selector_alex) print(negated_selector.covers(data).to_numpy()) print(f"instances with first name not equal to Alex {negated_selector.covers(data).to_numpy()}") ``` -------------------------------- ### IntervalSelector Example Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/sections/components/selectors.md Shows how to use IntervalSelector to select instances within a specified numerical range. The lower bound is inclusive, and the upper bound is exclusive. ```python from pysubgroup.datasets import load_allonesian_adults data = load_allonesian_adults() selector_age_interval = IntervalSelector("age", 18, 40) print(selector_age_interval.covers(data).to_numpy()) ``` -------------------------------- ### Subgroup Discovery Rule Example Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/readme.md This example illustrates a discovered subgroup as a rule, where a conjunctive description of selectors implies a specific outcome for the target concept. ```plaintext female=True AND age<50 AND drug_D = True ==> Operation_outcome=SUCCESS ``` -------------------------------- ### Check tox version and location Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/contributing.md Verify your tox installation and its Python version. This helps in troubleshooting errors during tox execution. ```shell tox --version # OR which tox ``` -------------------------------- ### Example Search Space Definition Source: https://github.com/flemmerich/pysubgroup/blob/master/examples/model_predictions_target.ipynb This snippet displays a complex search space definition, which includes various attributes with their possible values or ranges. This is typically used when setting up a subgroup discovery task. ```text Search space: [checking_status_b'0<=X<200'==False, checking_status_b'0<=X<200'==True, checking_status_b'<0'==True, checking_status_b'<0'==False, checking_status_b'>=200'==False, checking_status_b'>=200'==True, checking_status_b'no checking'==False, checking_status_b'no checking'==True, credit_history_b'all paid'==False, credit_history_b'all paid'==True, credit_history_b'critical/other existing credit'==False, credit_history_b'critical/other existing credit'==True, credit_history_b'delayed previously'==False, credit_history_b'delayed previously'==True, credit_history_b'existing paid'==True, credit_history_b'existing paid'==False, credit_history_b'no credits/all paid'==False, credit_history_b'no credits/all paid'==True, purpose_b'business'==False, purpose_b'business'==True, purpose_b'domestic appliance'==False, purpose_b'domestic appliance'==True, purpose_b'education'==False, purpose_b'education'==True, purpose_b'furniture/equipment'==True, purpose_b'furniture/equipment'==False, purpose_b'new car'==False, purpose_b'new car'==True, purpose_b'other'==False, purpose_b'other'==True, purpose_b'radio/tv'==False, purpose_b'radio/tv'==True, purpose_b'repairs'==False, purpose_b'repairs'==True, purpose_b'retraining'==False, purpose_b'retraining'==True, purpose_b'used car'==False, purpose_b'used car'==True, savings_status_b'100<=X<500'==False, savings_status_b'100<=X<500'==True, savings_status_b'500<=X<1000'==False, savings_status_b'500<=X<1000'==True, savings_status_b'<100'==True, savings_status_b'<100'==False, savings_status_b'>=1000'==False, savings_status_b'>=1000'==True, savings_status_b'no known savings'==False, savings_status_b'no known savings'==True, employment_b'1<=X<4'==True, employment_b'1<=X<4'==False, employment_b'4<=X<7'==False, employment_b'4<=X<7'==True, employment_b'<1'==False, employment_b'<1'==True, employment_b'>=7'==False, employment_b'>=7'==True, employment_b'unemployed'==False, employment_b'unemployed'==True, personal_status_b'female div/dep/mar'==True, personal_status_b'female div/dep/mar'==False, personal_status_b'male div/sep'==False, personal_status_b'male div/sep'==True, personal_status_b'male mar/wid'==False, personal_status_b'male mar/wid'==True, personal_status_b'male single'==False, personal_status_b'male single'==True, other_parties_b'co applicant'==False, other_parties_b'co applicant'==True, other_parties_b'guarantor'==False, other_parties_b'guarantor'==True, other_parties_b'none'==True, other_parties_b'none'==False, property_magnitude_b'car'==False, property_magnitude_b'car'==True, property_magnitude_b'life insurance'==False, property_magnitude_b'life insurance'==True, property_magnitude_b'no known property'==False, property_magnitude_b'no known property'==True, property_magnitude_b'real estate'==True, property_magnitude_b'real estate'==False, other_payment_plans_b'bank'==True, other_payment_plans_b'bank'==False, other_payment_plans_b'none'==False, other_payment_plans_b'none'==True, other_payment_plans_b'stores'==False, other_payment_plans_b'stores'==True, housing_b'for free'==False, housing_b'for free'==True, housing_b'own'==False, housing_b'own'==True, housing_b'rent'==True, housing_b'rent'==False, job_b'high qualif/self emp/mgmt'==False, job_b'high qualif/self emp/mgmt'==True, job_b'skilled'==True, job_b'skilled'==False, job_b'unemp/unskilled non res'==False, job_b'unemp/unskilled non res'==True, job_b'unskilled resident'==False, job_b'unskilled resident'==True, own_telephone_b'none'==True, own_telephone_b'none'==False, own_telephone_b'yes'==False, own_telephone_b'yes'==True, foreign_worker_b'no'==False, foreign_worker_b'no'==True, foreign_worker_b'yes'==True, foreign_worker_b'yes'==False, index<240, index: [240:440[, index: [440:634[, index: [634:825[, index>=825, duration<12.0, duration: [12.0:18.0[, duration: [18.0:24.0[, duration: [24.0:30.0[, duration>=30.0, credit_amount<1283.0, credit_amount: [1283.0:1845.0[, credit_amount: [1845.0:2762.0[, credit_amount: [2762.0:4583.0[, credit_amount>=4583.0, installment_commitment==1.0, installment_commitment==2.0, installment_commitment==3.0, installment_commitment==4.0, residence_since==1.0, residence_since==2.0, residence_since==3.0, residence_since==4.0, age<26.0, age: [26.0:31.0[, age: [31.0:36.0[, age: [36.0:43.0[, age>=43.0, existing_credits==1.0, existing_credits==2.0, existing_credits==3.0, existing_credits==4.0, num_dependents==1.0, num_dependents==2.0] ``` -------------------------------- ### Import pysubgroup module Source: https://github.com/flemmerich/pysubgroup/blob/master/README.md Import the pysubgroup module after installation. This is necessary to use the library's functionalities. ```python import pysubgroup ``` -------------------------------- ### Custom Selector Implementation Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/sections/components/selectors.md Provides an example of implementing a custom selector by creating a class that inherits from BaseSelector and implements the 'covers' function. This allows for flexible and specific data filtering. ```python from pysubgroup.datasets import load_allonesian_adults from pysubgroup.selector import BaseSelector class SubstringSelector(BaseSelector): def __init__(self, attribute, substring): self.attribute = attribute self.substring = substring def covers(self, data): return data[self.attribute].str.contains(self.substring, na=False) def __str__(self): return f"{self.attribute} contains '{self.substring}'" def __repr__(self): return str(self) data = load_allonesian_adults() selector_m = SubstringSelector("firstname", "m") print(selector_m.covers(data).to_numpy()) ``` -------------------------------- ### Install Package in Editable Mode Source: https://github.com/flemmerich/pysubgroup/blob/master/CONTRIBUTING.md Install the pysubgroup package in editable mode. This allows you to import the package directly from your local development files, making testing easier. ```bash pip install -U pip setuptools -e . ``` -------------------------------- ### Example DataFrame Result Source: https://github.com/flemmerich/pysubgroup/blob/master/examples/model_predictions_target.ipynb This shows a sample pandas DataFrame output after processing model results. It includes columns for 'quality', 'subgroup', and 'size_sg', representing the calculated quality score, the subgroup's condition, and its size, respectively. ```python Result: quality subgroup size_sg \ 0 16.119502 checking_status_b'no checking'==False 207 1 10.323862 checking_status_b'0<=X<200'==True 92 ``` -------------------------------- ### setup_from_quality_function Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/pysubgroup.md Sets up function pointers from the quality function. This is a utility for configuring the algorithm based on the quality function. ```APIDOC ## setup_from_quality_function(qf) ### Description Sets up function pointers from the quality function. ### Parameters * **qf** – The quality function used in the task. ``` -------------------------------- ### setup_constraints Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/pysubgroup.md Prepares constraints for use in the algorithm. This function configures the constraints for the subgroup discovery process. ```APIDOC ## setup_constraints(constraints, qf) ### Description Prepares constraints for use in the algorithm. ### Parameters * **constraints** (*list*) – List of constraints to apply. * **qf** – The quality function used in the task. ``` -------------------------------- ### Preview Documentation Locally Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/contributing.md Serve the compiled documentation using Python's built-in HTTP server to preview changes in a web browser. Ensure you are in the correct directory. ```bash python3 -m http.server --directory 'docs/_build/html' ``` -------------------------------- ### gp_prepare (MinSupportConstraint) Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/pysubgroup.md Prepares the MinSupportConstraint for the GP-Growth algorithm by accessing the size function. ```APIDOC ## gp_prepare (MinSupportConstraint) ### Description Prepares the MinSupportConstraint for the GP-Growth algorithm by accessing the size function. ### Method N/A (Method Call) ### Parameters * **qf**: The quality function used in the GP-Growth algorithm. ``` -------------------------------- ### Recreate tox environment for dependency issues Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/contributing.md If tox encounters missing dependencies, try recreating its environment using the -r flag. This is useful when setup.cfg or docs/requirements.txt are updated. ```shell tox -r -e docs ``` -------------------------------- ### Basic GP-Growth Usage Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/sections/components/gp_growth.md Demonstrates the standard way to use the GP-Growth algorithm with a dataset. Requires loading data, defining a target, creating a search space, and executing the task. ```python import pysubgroup as ps # Load the example dataset from pysubgroup.datasets import get_titanic_data data = get_titanic_data() target = ps.BinaryTarget ('Survived', True) searchspace = ps.create_selectors(data, ignore=['Survived']) task = ps.SubgroupDiscoveryTask (data, target, searchspace, result_set_size=5, depth=2, qf=ps.WRAccQF()) result = ps.GpGrowth().execute(task) ``` -------------------------------- ### Create Virtual Environment with virtualenv Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/contributing.md Set up an isolated Python environment using virtualenv. Activate the environment to manage project-specific dependencies. ```bash virtualenv source /bin/activate ``` -------------------------------- ### Compile Documentation with Tox Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/contributing.md Use tox to compile the documentation locally. This command ensures that the documentation is built using the project's defined build process. ```bash tox -e docs ``` -------------------------------- ### create_copy_of_tree_top_down Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/pysubgroup.md Creates a copy of a subtree starting from a specified root node using a top-down approach. It manages nodes, parent references, and class validity information. ```APIDOC ## create_copy_of_tree_top_down(from_root, nodes=None, parent=None, is_valid_class=None) ### Description Creates a copy of the tree starting from a specific root in top-down mode. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **from_root** (*GP_node*) – The root node to copy from. * **nodes** (*list*) – Optional. List to store the new nodes. * **parent** (*GP_node*) – Optional. The parent of the new root node. * **is_valid_class** (*dict*) – Optional. Dictionary indicating valid classes. ### Returns The new root node of the copied subtree. ### Return type GP_node ``` -------------------------------- ### create_initial_tree Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/pysubgroup.md Constructs the initial FP-tree based on provided coverage arrays. It returns the root node of the tree and a list of all nodes within it. ```APIDOC ## create_initial_tree(arrs) ### Description Creates the initial FP-tree from the coverage arrays. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **arrs** (*ndarray*) – A 2D NumPy array where each column corresponds to the coverage array of a selector. ### Returns A tuple containing: - root (GP_node): The root node of the tree. - nodes (list): A list of all nodes in the tree. ### Return type tuple ``` -------------------------------- ### Soft Classifier Target Setup Source: https://github.com/flemmerich/pysubgroup/blob/master/examples/model_predictions_target.ipynb Defines the target variable for subgroup discovery using soft classification. It specifies the columns containing the true labels and the model's predictions. ```python target = ps.SoftClassifierTarget(label_column, prediction_column) # tell pysubgroup based on which columns to evaluate the model ``` -------------------------------- ### BestFirstSearch.execute() Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Executes the Best-First Search algorithm for subgroup discovery. ```APIDOC ## BestFirstSearch.execute() ### Description Executes the Best-First Search algorithm to find subgroups. ### Method Not specified (likely a class method or instance method call). ### Endpoint Not applicable (Python method). ### Parameters Not specified in the source. ### Request Example Not specified in the source. ### Response Not specified in the source. ``` -------------------------------- ### Create Virtual Environment with Conda Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/contributing.md Initialize a Conda environment named 'pysubgroup' with specified Python packages. Activate the environment for development. ```bash conda create -n pysubgroup python=3 six virtualenv pytest pytest-cov conda activate pysubgroup ``` -------------------------------- ### Cleaning Build Artifacts (PyPI) Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/contributing.md Clean up the 'dist' and 'build' folders to ensure a clean release. This prevents confusion with old builds and Sphinx documentation. ```bash tox -e clean ``` ```bash rm -rf dist build ``` -------------------------------- ### Load and Prepare Credit Data Source: https://github.com/flemmerich/pysubgroup/blob/master/examples/model_predictions_target.ipynb Loads the credit dataset, preprocesses categorical features using one-hot encoding, and splits the data into training, subgroup discovery, and statistical verification sets. This prepares the data for model training and subgroup analysis. ```python import numpy as np import pandas as pd import pysubgroup as ps from pysubgroup.datasets import get_credit_data from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.metrics import RocCurveDisplay from sklearn.exceptions import ConvergenceWarning from warnings import simplefilter import matplotlib.pyplot as plt from tqdm.notebook import tqdm SEED = 0 data = get_credit_data() label_column = "class" prediction_column = "predictions" pos_label = "good" neg_label = "bad" # preprocessing data[label_column] = [pos_label if label == b'good' else neg_label for label in data[label_column]] categorical_features = ["checking_status", "credit_history", "purpose", "savings_status", "employment", "personal_status", "other_parties", "property_magnitude", "other_payment_plans", "housing", "job", "own_telephone", "foreign_worker"] other_columns = [column for column in data.columns if column not in categorical_features] data_categorical_dummies = pd.get_dummies(data.loc[:, categorical_features]) data_new = data_categorical_dummies data_new[other_columns] = data[other_columns] data = data_new # split data in 3 equal parts, each for: training, subgroup discovery, statistical verification of subgroups train_idx, other_idx = train_test_split(range(len(data)), test_size=0.66, random_state=SEED) sd_idx, stat_idx = train_test_split(other_idx, test_size=0.5, random_state=SEED) train_data = data.iloc[train_idx].reset_index() sd_data = data.iloc[sd_idx].reset_index() stat_data = data.iloc[stat_idx].reset_index() # grab the model inputs def get_X_y(split_data): split_X = split_data[split_data.columns[split_data.columns != label_column]] split_y = (split_data[label_column] == pos_label).astype("int64") return split_X, split_y train_X, train_y = get_X_y(train_data) sd_X, sd_y = get_X_y(sd_data) stat_X, stat_y = get_X_y(stat_data) # train simplefilter("ignore", ConvergenceWarning) model = LogisticRegression(penalty="l2", random_state=SEED) model.fit(train_X, train_y) # predict train_data[prediction_column] = model.predict_proba(train_X)[:, 1] sd_data[prediction_column] = model.predict_proba(sd_X)[:, 1] stat_data[prediction_column] = model.predict_proba(stat_X)[:, 1] ``` -------------------------------- ### GeneralisingBFS.execute() Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Executes the Generalizing Breadth-First Search (BFS) algorithm for subgroup discovery. ```APIDOC ## GeneralisingBFS.execute() ### Description Executes the Generalizing Breadth-First Search (BFS) algorithm to find subgroups. ### Method Not specified (likely a class method or instance method call). ### Endpoint Not applicable (Python method). ### Parameters Not specified in the source. ### Request Example Not specified in the source. ### Response Not specified in the source. ``` -------------------------------- ### BaseTarget Methods Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Documentation for methods within the BaseTarget class. ```APIDOC ## BaseTarget.all_statistics_present() ### Description Checks if all statistics are present for the BaseTarget. ### Method (Not specified, likely a class method or instance method) ### Endpoint (Not applicable, SDK method) ### Parameters (None specified) ### Request Example (Not applicable) ### Response (Not specified, likely a boolean) ``` -------------------------------- ### Basic Pysubgroup Usage with Titanic Data Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/tutorials/introduction.ipynb Demonstrates a simple use case of pysubgroup with the titanic dataset. Requires importing the pysubgroup library. ```python import pysubgroup as ps ``` -------------------------------- ### pysubgroup.utils Module Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Documentation for the pysubgroup.utils module. ```APIDOC ## Module: pysubgroup.utils This module contains utility functions for the pysubgroup library. ``` -------------------------------- ### Pushing Tags (PyPI) Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/contributing.md Push the newly created tag to the upstream repository. This action triggers automated releases on platforms like GitHub Actions. ```bash git push --tags ``` -------------------------------- ### Prepare and Analyze Numeric Data Source: https://github.com/flemmerich/pysubgroup/blob/master/examples/numeric_targets.ipynb Prepares sample data, defines a numeric target and an equality selector, and computes statistics and quality function evaluations. Ensure data is converted to appropriate types. ```python import pandas as pd import numpy as np import pysubgroup as ps # Generate some minimal example data data = np.array([[1., 2., 3., 4., 5.], ["F", "F", "F", "Tr", "Tr"]]).T data = pd.DataFrame(data, columns=["Target", "A"]) data["Target"] = data["Target"].astype(float) # Define target and an examples selector target = ps.NumericTarget("Target") sgd = ps.EqualitySelector("A", "Tr") # Compute statistics, the quality, and the optimistic estimate of the subgroup target.calculate_statistics(sgd, data) qf = ps.StandardQFNumeric(.5) print(qf.evaluate(sgd, target, data)) print(qf.optimistic_estimate(sgd, target, data)) ``` -------------------------------- ### GP-Growth String Representation of Valuation Basis Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/sections/components/gp_growth.md Provides the method signature for converting a valuation basis into a string representation for debugging purposes within the GP-Growth algorithm. ```python def gp_to_str(self, basis) -> str: """ returns a string representation of the valuation basis """ pass ``` -------------------------------- ### SimpleCountQF Methods Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Methods for the SimpleCountQF class, a quality function for calculating simple counts. ```APIDOC ## SimpleCountQF Methods ### Description Implements a quality function for calculating simple counts, with methods for statistics calculation and parameter retrieval. ### Methods - `calculate_constant_statistics()` - `calculate_statistics()` - `gp_get_null_vector()` - `gp_get_params()` - `gp_get_stats()` - `gp_merge()` - `gp_to_str()` ### Properties - `gp_requires_cover_arr` - `gp_size_sg()` - `tpl` ``` -------------------------------- ### supportSetVisualization Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/pysubgroup.md Visualizes the support set of subgroups. ```APIDOC ## supportSetVisualization ### Description Visualizes the support set of subgroups. ### Parameters - **result**: The result object from subgroup discovery. - **in_order** (bool, optional): Whether to display subgroups in order. Defaults to True. - **drop_empty** (bool, optional): Whether to drop empty support sets. Defaults to True. ``` -------------------------------- ### Define and Execute Subgroup Discovery Task Source: https://github.com/flemmerich/pysubgroup/blob/master/examples/model_predictions_target.ipynb This snippet shows how to define a SubgroupDiscoveryTask with various parameters and then execute it using the BestFirstSearch algorithm. It's useful for initiating a subgroup discovery process. ```python task = ps.SubgroupDiscoveryTask( sd_data, target, searchspace, result_set_size=100, depth=5, qf=qf, min_quality=0, constraints=constraints, ) result = ps.BestFirstSearch().execute(task) # run the search algorithm print(f"Result: {result.results}") ``` -------------------------------- ### execute Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/pysubgroup.md Executes the GP-Growth algorithm for subgroup discovery based on a provided task. It returns the result of the discovery process. ```APIDOC ## execute(task) ### Description Executes the GP-Growth algorithm on the given task. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **task** (*SubgroupDiscoveryTask*) – The subgroup discovery task to execute. ### Returns The result of the subgroup discovery. ### Return type SubgroupDiscoveryResult ``` -------------------------------- ### prepare_selectors Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/pysubgroup.md Prepares the selectors by computing their coverage arrays and filtering based on constraints. This is a utility function for subgroup discovery. ```APIDOC ## prepare_selectors(search_space, data) ### Description Prepares the selectors by computing their coverage arrays and filtering based on constraints. ### Parameters * **search_space** (*list*) – The list of selectors to consider. * **data** (*DataFrame*) – The dataset to be analyzed. ### Returns A tuple containing: - selectors_sorted (list): The sorted list of selectors after filtering. - arrs (ndarray): A 2D NumPy array where each column corresponds to the coverage array of a selector. ### Return type tuple ``` -------------------------------- ### Apriori.execute() Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Executes the Apriori algorithm for subgroup discovery. ```APIDOC ## Apriori.execute() ### Description Executes the Apriori algorithm to find subgroups. ### Method Not specified (likely a class method or instance method call). ### Endpoint Not applicable (Python method). ### Parameters Not specified in the source. ### Request Example Not specified in the source. ### Response Not specified in the source. ``` -------------------------------- ### SimpleSearch.execute() Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Executes the Simple Search algorithm for subgroup discovery. ```APIDOC ## SimpleSearch.execute() ### Description Executes the Simple Search algorithm to find subgroups. ### Method Not specified (likely a class method or instance method call). ### Endpoint Not applicable (Python method). ### Parameters Not specified in the source. ### Request Example Not specified in the source. ### Response Not specified in the source. ``` -------------------------------- ### Apriori.get_next_level_candidates() Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Generates candidate subgroups for the next level using the Apriori algorithm. ```APIDOC ## Apriori.get_next_level_candidates() ### Description Generates candidate subgroups for the next level in the Apriori algorithm. ### Method Not specified (likely a class method or instance method call). ### Endpoint Not applicable (Python method). ### Parameters Not specified in the source. ### Request Example Not specified in the source. ### Response Not specified in the source. ``` -------------------------------- ### SimpleDFS.execute() Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Executes the Simple Depth-First Search (DFS) algorithm for subgroup discovery. ```APIDOC ## SimpleDFS.execute() ### Description Executes the Simple Depth-First Search (DFS) algorithm to find subgroups. ### Method Not specified (likely a class method or instance method call). ### Endpoint Not applicable (Python method). ### Parameters Not specified in the source. ### Request Example Not specified in the source. ### Response Not specified in the source. ``` -------------------------------- ### pysubgroup.subgroup_description Module Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Documentation for the subgroup_description module, including classes like Conjunction, DNF, Disjunction, EqualitySelector, IntervalSelector, NegatedSelector, and SelectorBase, as well as various utility functions. ```APIDOC ## Module: pysubgroup.subgroup_description ### Classes: * **Conjunction** * `pop_or()` * `selectors` * **DNF** * `append_and()` * `append_or()` * `pop_and()` * **Disjunction** * `append_and()` * `append_or()` * `covers()` * `selectors` * **EqualitySelector** * `attribute_name` * `attribute_value` * `compute_descriptions()` * `covers()` * `from_str()` * `selectors` * `set_descriptions()` * **IntervalSelector** * `attribute_name` * `compute_descriptions()` * `compute_string()` * `covers()` * `from_str()` * `lower_bound` * `selectors` * `set_descriptions()` * `upper_bound` * **NegatedSelector** * `attribute_name` * `covers()` * `selectors` * `set_descriptions()` * **SelectorBase** * `set_descriptions()` ### Functions: * `create_nominal_selectors()` * `create_nominal_selectors_for_attribute()` * `create_numeric_selectors()` * `create_numeric_selectors_for_attribute()` * `create_selectors()` * `get_cover_array_and_size()` * `get_size()` * `pandas_sparse_eq()` * `remove_target_attributes()` ``` -------------------------------- ### Basic Subgroup Discovery with Titanic Dataset Source: https://github.com/flemmerich/pysubgroup/blob/master/README.md This snippet demonstrates a simple use case for subgroup discovery using the Titanic dataset. It involves loading data, defining a target, creating a search space, setting up a discovery task, and executing the search. ```python import pysubgroup as ps # Load the example dataset from pysubgroup.datasets import get_titanic_data data = get_titanic_data() target = ps.BinaryTarget ('Survived', True) searchspace = ps.create_selectors(data, ignore=['Survived']) task = ps.SubgroupDiscoveryTask ( data, target, searchspace, result_set_size=5, depth=2, qf=ps.WRAccQF()) result = ps.DFS().execute(task) ``` -------------------------------- ### GeneralizationAware_StandardQF.evaluate() Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Evaluates the Generalization-Aware Standard Quality Function. ```APIDOC ## GeneralizationAware_StandardQF.evaluate() ### Description Evaluates the Generalization-Aware Standard Quality Function for a given subgroup. ### Method Not specified (likely a class method or instance method call). ### Endpoint Not applicable (Python method). ### Parameters Not specified in the source. ### Request Example Not specified in the source. ### Response Not specified in the source. ``` -------------------------------- ### GeneralizationAware_StandardQF.max_based_optimistic_estimate() Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Calculates the max-based optimistic estimate for Generalization-Aware Standard QF. ```APIDOC ## GeneralizationAware_StandardQF.max_based_optimistic_estimate() ### Description Calculates the max-based optimistic estimate for the Generalization-Aware Standard Quality Function. ### Method Not specified (likely a class method or instance method call). ### Endpoint Not applicable (Python method). ### Parameters Not specified in the source. ### Request Example Not specified in the source. ### Response Not specified in the source. ``` -------------------------------- ### BaseSoftClassifierPerformanceQF Initialization Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/pysubgroup.md Initializes the base class for soft classifier performance quality functions. It requires a performance measure, its type (score or loss), and optional constraints and weighting factors for subgroup size and class balance. ```python BaseSoftClassifierPerformanceQF(performance_measure, performance_measure_type: Literal['score', 'loss'], performance_measure_bound=None, performance_measure_constraints: list[any] = [], subgroup_class_balance_weight: float = 0, subgroup_size_weight: float = 0) ``` -------------------------------- ### Tagging a Release (PyPI) Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/contributing.md Tag the current commit on the main branch with a release tag. This is a crucial step before pushing the release to PyPI. ```bash git tag -a 0.7.7 -m "Release 0.7.7" ``` -------------------------------- ### GeneralizationAware_StandardQF.max_based_aggregate_statistics() Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Calculates max-based aggregate statistics for Generalization-Aware Standard QF. ```APIDOC ## GeneralizationAware_StandardQF.max_based_aggregate_statistics() ### Description Calculates max-based aggregate statistics for the Generalization-Aware Standard Quality Function. ### Method Not specified (likely a class method or instance method call). ### Endpoint Not applicable (Python method). ### Parameters Not specified in the source. ### Request Example Not specified in the source. ### Response Not specified in the source. ``` -------------------------------- ### BeamSearch.execute() Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Executes the Beam Search algorithm for subgroup discovery. ```APIDOC ## BeamSearch.execute() ### Description Executes the Beam Search algorithm to find subgroups. ### Method Not specified (likely a class method or instance method call). ### Endpoint Not applicable (Python method). ### Parameters Not specified in the source. ### Request Example Not specified in the source. ### Response Not specified in the source. ``` -------------------------------- ### GeneralizationAware_StandardQF.difference_based_optimistic_estimate() Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Calculates the difference-based optimistic estimate for Generalization-Aware Standard QF. ```APIDOC ## GeneralizationAware_StandardQF.difference_based_optimistic_estimate() ### Description Calculates the difference-based optimistic estimate for the Generalization-Aware Standard Quality Function. ### Method Not specified (likely a class method or instance method call). ### Endpoint Not applicable (Python method). ### Parameters Not specified in the source. ### Request Example Not specified in the source. ### Response Not specified in the source. ``` -------------------------------- ### pysubgroup.binary_target Source: https://github.com/flemmerich/pysubgroup/blob/master/docs/api/modules.md Provides quality functions for binary targets, including GeneralizationAware_StandardQF, LiftQF, SimpleBinomialQF, SimplePositivesQF, StandardQF, and WRAccQF. ```APIDOC ## Module: pysubgroup.binary_target ### Description Provides quality functions for binary targets. ### Classes - `GeneralizationAware_StandardQF` - `LiftQF` - `SimpleBinomialQF` - `SimplePositivesQF` - `StandardQF` - `WRAccQF` ### Methods #### `GeneralizationAware_StandardQF.max_based_read_p()` - **Description**: Calculates a value based on max-based read. - **Usage**: `GeneralizationAware_StandardQF.max_based_read_p()` ``` ```APIDOC ## Class: SimplePositivesQF ### Description Represents a quality function for simple positives. ### Methods - `calculate_constant_statistics()` - `calculate_statistics()` - `gp_get_null_vector()` - `gp_get_params()` - `gp_get_stats()` - `gp_merge()` - `gp_requires_cover_arr` - `gp_size_sg()` - `gp_to_str()` - `tpl` ``` ```APIDOC ## Class: StandardQF ### Description Represents a standard quality function. ### Methods - `evaluate()` - `optimistic_estimate()` - `optimistic_generalisation()` - `standard_qf()` ```