<jupyter_start><jupyter_text>Example of emmv library using scikit-learn<jupyter_code># Install emmv

! pip install --user emmv
# Imports

from emmv import emmv_scores
import numpy as np
from sklearn.ensemble import IsolationForest
# Create data, fit a model and retrieve EM/MV scores

rng = np.random.RandomState(42)

# Data and model fitting adapted from: https://scikit-learn.org/stable/auto_examples/ensemble/plot_isolation_forest.html
NUM_COLS = 2
# Generate train data
X = 0.3 * rng.randn(100, NUM_COLS)
X_train = np.r_[X + 2, X - 2]
# Generate some regular novel observations
X = 0.3 * rng.randn(20, NUM_COLS)
X_regular = np.r_[X + 2, X - 2]
# Generate some abnormal novel observations
X_outliers = rng.uniform(low=-4, high=4, size=(20, NUM_COLS))
# fit the model
model = IsolationForest(max_samples=100, random_state=rng)
model.fit(X_train)

# Get EM & MV scores
X_test = np.concatenate((X_regular, X_outliers), axis=0)
test_scores = emmv_scores(model, X_test)
print('Excess Mass score;', test_scores['em'])
print('Mass Volume score:', test_scores['mv'])<jupyter_output>Excess Mass score; 0.07170818386666666
Mass Volume score: 45.02629787785894
{'fraction_non_alphanumeric': 0.10932203389830508, 'fraction_numerical': 0.04915254237288136, 'mean_word_length': 4.817733990147783, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '598131', 'license': 'MIT', 'n_tokens_mistral': 489, 'n_tokens_neox': 438, 'n_words': 114, 'path': 'examples/sklearn_example.ipynb', 'repo_name': 'christian-oleary/emmv', 'size': '1180'}