### Install scikit-garden from source Source: https://onelearn.readthedocs.io/en/latest/_sources/experiments.rst.txt Clones the scikit-garden repository and installs it via setup.py to get the latest version, required for comparison with Mondrian forests. ```bash git clone https://github.com/scikit-garden/scikit-garden.git && \ cd scikit-garden && \ python setup.py build install ``` -------------------------------- ### Install onelearn from GitHub Source: https://onelearn.readthedocs.io/en/latest/_sources/index.rst.txt Install the latest development version of onelearn directly from GitHub. ```bash pip install git+https://github.com/onelearn/onelearn.git ``` -------------------------------- ### Run tree playground with run_playground_tree Source: https://onelearn.readthedocs.io/en/latest/_sources/playground.rst.txt Starts the tree playground. Requires streamlit, bokeh, and matplotlib. Use after pip installing onelearn. ```python from onelearn import run_playground_tree run_playground_tree() ``` -------------------------------- ### Install onelearn via pip Source: https://onelearn.readthedocs.io/en/latest/_sources/index.rst.txt Install onelearn from PyPI using pip. ```bash pip install onelearn ``` -------------------------------- ### Run decision function playground with run_playground_decision Source: https://onelearn.readthedocs.io/en/latest/_sources/playground.rst.txt Starts the decision function playground. Requires streamlit, bokeh, and matplotlib. Use after pip installing onelearn. ```python from onelearn import run_playground_decision run_playground_decision() ``` -------------------------------- ### Run scripts to reproduce paper figures Source: https://onelearn.readthedocs.io/en/latest/_sources/experiments.rst.txt Commands to run the example scripts that reproduce all figures from the paper. Note that run_* scripts can take a while, especially run_regrets_experiments.py. ```bash python examples/plot_iterations.py ``` ```bash python examples/plot_decisions.py ``` ```bash python examples/plot_forest_effect.py ``` ```bash python examples/run_regrets_experiments.py ``` ```bash python examples/run_online_vs_batch.py ``` ```bash python examples/run_n_trees_sensitivity.py ``` -------------------------------- ### RandomForestClassifier Source: https://onelearn.readthedocs.io/en/latest/auto_examples/plot_decisions.html RandomForestClassifier from scikit-learn is used in the example. It is instantiated with n_estimators and random_state. It supports fit and predict_proba methods. ```APIDOC ## RandomForestClassifier ### Description RandomForestClassifier is a random forest classifier from scikit-learn. It is used in the example to compare decision functions with other classifiers. ### Constructor Parameters - **n_estimators** (int) - Required - Number of estimators in the forest. - **random_state** (int) - Required - Random state for reproducibility. ### Methods #### fit(X, y) Fits the classifier on the given data. #### predict_proba(X) Returns probability estimates for the input samples. ### Example Usage ```python from sklearn.ensemble import RandomForestClassifier clf = RandomForestClassifier(n_estimators=100, random_state=42) clf.fit(X, y) Z = clf.predict_proba(X_mesh)[:, 1].reshape(xx.shape) ``` ``` -------------------------------- ### ExtraTreesClassifier Source: https://onelearn.readthedocs.io/en/latest/auto_examples/plot_decisions.html ExtraTreesClassifier from scikit-learn is used in the example. It is instantiated with n_estimators and random_state. It supports fit and predict_proba methods. ```APIDOC ## ExtraTreesClassifier ### Description ExtraTreesClassifier is an extra trees classifier from scikit-learn. It is used in the example to compare decision functions with other classifiers. ### Constructor Parameters - **n_estimators** (int) - Required - Number of estimators in the forest. - **random_state** (int) - Required - Random state for reproducibility. ### Methods #### fit(X, y) Fits the classifier on the given data. #### predict_proba(X) Returns probability estimates for the input samples. ### Example Usage ```python from sklearn.ensemble import ExtraTreesClassifier clf = ExtraTreesClassifier(n_estimators=100, random_state=42) clf.fit(X, y) Z = clf.predict_proba(X_mesh)[:, 1].reshape(xx.shape) ``` ``` -------------------------------- ### MondrianForestClassifier Source: https://onelearn.readthedocs.io/en/latest/auto_examples/plot_decisions.html MondrianForestClassifier from scikit-garden is used in the example. It is instantiated with n_estimators and random_state. It supports fit and predict_proba methods. ```APIDOC ## MondrianForestClassifier ### Description MondrianForestClassifier is a random forest type classifier from scikit-garden. It is used in the example to compare decision functions with other classifiers. ### Constructor Parameters - **n_estimators** (int) - Required - Number of estimators in the forest. - **random_state** (int) - Required - Random state for reproducibility. ### Methods #### fit(X, y) Fits the classifier on the given data. #### predict_proba(X) Returns probability estimates for the input samples. ### Example Usage ```python from skgarden import MondrianForestClassifier clf = MondrianForestClassifier(n_estimators=100, random_state=42) clf.fit(X, y) Z = clf.predict_proba(X_mesh)[:, 1].reshape(xx.shape) ``` ``` -------------------------------- ### AMFClassifier Source: https://onelearn.readthedocs.io/en/latest/auto_examples/plot_decisions.html The AMFClassifier from onelearn is used in the example. It is instantiated with parameters such as n_classes, n_estimators, random_state, use_aggregation, and split_pure. The classifier supports partial_fit and predict_proba methods. ```APIDOC ## AMFClassifier ### Description AMFClassifier is a random forest type classifier from onelearn. It is used in the example to compare decision functions with other classifiers. ### Constructor Parameters - **n_classes** (int) - Required - Number of classes. - **n_estimators** (int) - Required - Number of estimators in the forest. - **random_state** (int) - Required - Random state for reproducibility. - **use_aggregation** (bool) - Required - Whether to use aggregation. - **split_pure** (bool) - Required - Whether to split pure nodes. ### Methods #### partial_fit(X, y) Incrementally fits the classifier on the given data. #### predict_proba(X) Returns probability estimates for the input samples. ### Example Usage ```python from onelearn import AMFClassifier clf = AMFClassifier( n_classes=2, n_estimators=100, random_state=42, use_aggregation=True, split_pure=True, ) clf.partial_fit(X, y) Z = clf.predict_proba(X_mesh)[:, 1].reshape(xx.shape) ``` ``` -------------------------------- ### Run tree playground with streamlit Source: https://onelearn.readthedocs.io/en/latest/_sources/playground.rst.txt Alternative way to run the tree playground when onelearn is git cloned. Executes the streamlit app from examples/playground_tree.py. ```bash streamlit run examples/playground_tree.py ``` -------------------------------- ### AMFClassifier.__init__ Source: https://onelearn.readthedocs.io/en/latest/_sources/generated/onelearn.AMFClassifier.rst.txt Initializes the AMFClassifier instance. ```APIDOC ## AMFClassifier.__init__ ### Description Initializes the AMFClassifier instance. ### Method Constructor ### Signature `__init__(self, ...)` ### Parameters No parameters are explicitly documented in the source. ### Returns None ``` -------------------------------- ### Generate onelearn logo with AMFClassifier Source: https://onelearn.readthedocs.io/en/latest/_sources/auto_examples/plot_logo.rst.txt Runs the full logo-generation script: imports libraries, sets up logging, creates a two-class dataset with make_moons, splits into train/test, computes a meshgrid, trains an AMFClassifier with partial_fit over several iterations, plots decision contours and scatter points, and saves the figure as logo.png. The script prints progress bar output from tqdm. ```python import sys import logging import matplotlib.pyplot as plt from tqdm import trange from sklearn.datasets import make_moons from sklearn.metrics import roc_auc_score from sklearn.model_selection import train_test_split sys.path.extend([".", ".."]) from onelearn import AMFClassifier from experiments.plot import ( get_mesh, plot_contour_binary_classif, plot_scatter_binary_classif, ) logging.basicConfig( format="%(asctime)s %(message)s", datefmt="%Y/%m/%d %H:%M:%S", level=logging.INFO ) n_samples = 100 n_features = 2 n_classes = 2 random_state = 123 save_iterations = [5, 10, 30, 70] logging.info("Simulation of the data") X, y = make_moons(n_samples=n_samples, noise=0.25, random_state=random_state) logging.info("Train/Test splitting") X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.5, random_state=random_state ) logging.info("Computation of the meshgrid") xx, yy, X_mesh = get_mesh(X) clf = AMFClassifier( n_classes=n_classes, n_estimators=100, random_state=random_state, split_pure=True, use_aggregation=True, ) n_plots = len(save_iterations) n_fig = 0 save_iterations = [0, *save_iterations] plt.figure(figsize=(3, 3)) logging.info("Launching iterations") bar = trange(n_plots, desc="Plotting iterations", leave=True) norm = plt.Normalize(vmin=0.0, vmax=1.0) for start, end in zip(save_iterations[:-1], save_iterations[1:]): X_iter = X_train[start:end] y_iter = y_train[start:end] clf.partial_fit(X_iter, y_iter) n_fig += 1 Z = clf.predict_proba(X_mesh)[:, 1].reshape(xx.shape) ax = plt.subplot(2, 2, n_fig) score = roc_auc_score(y_test, clf.predict_proba(X_test)[:, 1]) plot_contour_binary_classif(ax, xx, yy, Z, levels=5, norm=norm) plot_scatter_binary_classif( ax, xx, yy, X_train[:end], y_train[:end], s=15, norm=norm ) bar.update(1) bar.close() plt.subplots_adjust(wspace=0, hspace=0) plt.savefig("logo.png", transparent=True) logging.info("Saved logo in file logo.png") ``` ```none Plotting iterations: 0%| | 0/4 [00:00