<jupyter_start><jupyter_text>BenchmarkCe notebook compare différents modèles depuis un notebook.<jupyter_code>from jyquickhelper import add_notebook_menu
add_notebook_menu()<jupyter_output><empty_output><jupyter_text>Si le message *Widget Javascript not detected. It may not be installed or enabled properly.* apparaît, vous devriez exécuter la commande ``jupyter nbextension enable --py --sys-prefix widgetsnbextension`` depuis la ligne de commande. Le code suivant vous permet de vérifier que cela a été fait.<jupyter_code>from tqdm import tnrange, tqdm_notebook
from time import sleep

for i in tnrange(3, desc='1st loop'):
    for j in tqdm_notebook(range(20), desc='2nd loop'):
        sleep(0.01)
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Petit bench sur le clustering  Définition du bench<jupyter_code>import dill
from tqdm import tnrange
from sklearn.cluster import AgglomerativeClustering, KMeans
from sklearn.datasets import make_blobs
from mlstatpy.ml import MlGridBenchMark

params = [dict(model=lambda : KMeans(n_clusters=3), name="KMeans-3", shortname="km-3"),
          dict(model=lambda : AgglomerativeClustering(), name="AgglomerativeClustering", shortname="aggclus")]

datasets = [dict(X=make_blobs(100, centers=3)[0], Nclus=3,
                 name="blob-100-3", shortname="b-100-3", no_split=True),
            dict(X=make_blobs(100, centers=5)[0], Nclus=5, 
                 name="blob-100-5", shortname="b-100-5", no_split=True) ]

bench = MlGridBenchMark("TestName", datasets, fLOG=None, clog=None,
                        cache_file="cache.pickle", pickle_module=dill, 
                        repetition=3, progressbar=tnrange,
                        graphx=["_time", "time_train", "Nclus"],
                        graphy=["silhouette", "Nrows"])<jupyter_output><empty_output><jupyter_text>Lancer le bench<jupyter_code>bench.run(params)<jupyter_output><empty_output><jupyter_text>Récupérer les résultats<jupyter_code>df = bench.to_df()
df
df.plot(x="time_train", y="silhouette", kind="scatter")<jupyter_output><empty_output><jupyter_text>Dessin, Graphs<jupyter_code>bench.plot_graphs(figsize=(12,12))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11667432246210381, 'fraction_numerical': 0.020211299954065228, 'mean_word_length': 5.117977528089888, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '66632', 'license': 'MIT', 'n_tokens_mistral': 790, 'n_tokens_neox': 754, 'n_words': 149, 'path': '_doc/notebooks/ml/benchmark.ipynb', 'repo_name': 'Pandinosaurus/mlstatpy', 'size': '2177'}