<jupyter_start><jupyter_text>Scikit-learn + Neptune Neptune helps you keep track of your machine learning runs and if you are using scikit-learn you can add tracking very easily.This quickstart will show you how to (using just single function) log scikit-learn:* regression summary,* classification summary,* kmeans clustering summary.  Before you start  Install dependencies<jupyter_code>! pip install neptune-client neptune-sklearn scikit-learn==0.24.1<jupyter_output><empty_output><jupyter_text>Scikit-learn regression  Create and fit random forest regressor Define regressor parameters, that will be later passed to Neptune.<jupyter_code>parameters = {"n_estimators": 70, "max_depth": 7, "min_samples_split": 3}<jupyter_output><empty_output><jupyter_text>Create and fit regressor.<jupyter_code>from sklearn.datasets import load_boston
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split

rfr = RandomForestRegressor(**parameters)

X, y = load_boston(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.20, random_state=28743
)

rfr.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Initialize Neptune Connect your script to Neptune application and create new run.<jupyter_code>import neptune.new as neptune

run = neptune.init(
    project="common/sklearn-integration",
    api_token="<PASSWORD>",
    name="regression-example",
    tags=["RandomForestRegressor", "regression"],
)<jupyter_output><empty_output><jupyter_text>Click on the link above to open this run in Neptune. For now it is empty but keep the tab with run open to see what happens next. You tell Neptune: * **who you are**: your Neptune API token `api_token` * **where you want to send your data**: your Neptune `project`.At this point you have new run in Neptune. For now on you will use `run` to log metadata to it.---**Note**Instead of logging data to the public project `'common/sklearn-integration'` as an anonymous user 'neptuner' you can log it to your own project.To do that:1. Get your [Neptune API token](https://docs.neptune.ai/getting-started/installationget-api-token)2. Pass the token to ``api_token`` argument of ``neptune.init()`` method: ``api_token=YOUR_API_TOKEN``3. Pass your project to the ``project`` argument of the ``neptune.init()``.For example:```pythonneptune.init(project='my_workspace/my_project',              api_token='<PASSWORD>')```  Log regressor summary<jupyter_code>import neptune.new.integrations.sklearn as npt_utils

run["rfr_summary"] = npt_utils.create_regressor_summary(
    rfr, X_train, X_test, y_train, y_test
)<jupyter_output><empty_output><jupyter_text>You just logged information about the regressor, including:* [logged regressor parameters](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/all?path=rfr_summary%2Fall_params),* [logged pickled model](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/all?path=rfr_summary%2F&attribute=pickled_model),* [logged test predictions](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/all?path=rfr_summary%2Ftest&attribute=preds),* [logged test scores](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/all?path=rfr_summary%2Ftest%2Fscores),* [logged regressor visualizations](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/all?path=rfr_summary%2Fdiagnostics_charts&attribute=feature_importance),* [logged metadata](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/all?path=sys),* [logged code and git metadata](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/source-code?file=main.py).  Stop logging**Warning:**Once you are done logging, you should stop tracking the run using the `stop()` method.This is needed only while logging from a notebook environment. While logging through a script, Neptune automatically stops tracking once the script has completed execution.<jupyter_code>run.stop()<jupyter_output><empty_output><jupyter_text>Explore results You just learned how to log scikit-learn regression summary to Neptune using single function.Click on the link that was outputted to the console or [go here](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/all) to explore a run similar to yours. In particular check:* [logged regressor parameters](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/all?path=rfr_summary%2Fall_params),* [logged pickled model](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/all?path=rfr_summary%2F&attribute=pickled_model),* [logged test predictions](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/all?path=rfr_summary%2Ftest&attribute=preds),* [logged test scores](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/all?path=rfr_summary%2Ftest%2Fscores),* [logged regressor visualizations](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/all?path=rfr_summary%2Fdiagnostics_charts&attribute=feature_importance),* [logged metadata](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/all?path=sys),* [logged code and git metadata](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-92/source-code?file=main.py).  Scikit-learn classification  Create and fit gradient boosting classifier Define classifier parameters, that will be later passed to Neptune.<jupyter_code>parameters = {
    "n_estimators": 120,
    "learning_rate": 0.12,
    "min_samples_split": 3,
    "min_samples_leaf": 2,
}<jupyter_output><empty_output><jupyter_text>Create and fit regressor.<jupyter_code>from sklearn.datasets import load_digits
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.model_selection import train_test_split

gbc = GradientBoostingClassifier(**parameters)

X, y = load_digits(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.20, random_state=28743
)

gbc.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Initialize Neptune Connect your script to Neptune application and create new run.<jupyter_code>import neptune.new as neptune

run = neptune.init(
    project="common/sklearn-integration",
    api_token="<PASSWORD>",
    name="classification-example",
    tags=["GradientBoostingClassifier", "classification"],
)<jupyter_output><empty_output><jupyter_text>Click on the link above to open this run in Neptune. For now it is empty but keep the tab with run open to see what happens next. You tell Neptune: * **who you are**: your Neptune API token `api_token` * **where you want to send your data**: your Neptune `project`.At this point you have new run in Neptune. For now on you will use `run` to log metadata to it.---**Note**Instead of logging data to the public project `'common/sklearn-integration'` as an anonymous user 'neptuner' you can log it to your own project.To do that:1. Get your [Neptune API token](https://docs.neptune.ai/getting-started/installationget-api-token)2. Pass the token to ``api_token`` argument of ``neptune.init()`` method: ``api_token=YOUR_API_TOKEN``3. Pass your project to the ``project`` argument of the ``neptune.init()``.For example:```pythonneptune.init(project='my_workspace/my_project',              api_token='<PASSWORD>')```  Log classifier summary<jupyter_code>import neptune.new.integrations.sklearn as npt_utils

run["cls_summary"] = npt_utils.create_classifier_summary(
    gbc, X_train, X_test, y_train, y_test
)<jupyter_output><empty_output><jupyter_text>You just logged information about the classifier, including:* [logged classifier parameters](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/all?path=cls_summary%2Fall_params),* [logged pickled model](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/all?path=cls_summary%2F&attribute=pickled_model),* [logged test predictions](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/all?path=cls_summary%2Ftest&attribute=preds),* [logged test predictions probabilities](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/all?path=cls_summary%2Ftest&attribute=preds_proba),* [logged test scores](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/all?path=cls_summary%2Ftest%2Fscores%2F),* [logged classifier visualizations](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/all?path=cls_summary%2Fdiagnostics_charts&attribute=class_prediction_error),* [logged metadata](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/all?path=sys),* [logged code and git metadata](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/source-code?file=main.py&filePath=integrations%2Fsklearn%2F).  Stop logging**Warning:**Once you are done logging, you should stop tracking the run using the `stop()` method.This is needed only while logging from a notebook environment. While logging through a script, Neptune automatically stops tracking once the script has completed execution.<jupyter_code>run.stop()<jupyter_output><empty_output><jupyter_text>Explore Results You just learned how to log scikit-learn classification summary to Neptune using single function.Click on the link that was outputted to the console or [go here](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/allhttps://ui.neptune.ai/o/shared/org/sklearn-integration/e/SKLEARN-312/charts) to explore a run similar to yours. In particular check:* [logged classifier parameters](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/all?path=cls_summary%2Fall_params),* [logged pickled model](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/all?path=cls_summary%2F&attribute=pickled_model),* [logged test predictions](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/all?path=cls_summary%2Ftest&attribute=preds),* [logged test predictions probabilities](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/all?path=cls_summary%2Ftest&attribute=preds_proba),* [logged test scores](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/all?path=cls_summary%2Ftest%2Fscores%2F),* [logged classifier visualizations](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/all?path=cls_summary%2Fdiagnostics_charts&attribute=class_prediction_error),* [logged metadata](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/all?path=sys),* [logged code and git metadata](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-95/source-code?file=main.py&filePath=integrations%2Fsklearn%2F).  Scikit-learn KMeans clustering  Create KMeans object and example data Define KMeans clustering parameters, that will be later passed to Neptune.<jupyter_code>parameters = {"n_init": 11, "max_iter": 270}<jupyter_output><empty_output><jupyter_text>Create and fit KMeans model.<jupyter_code>from sklearn.datasets import make_blobs
from sklearn.cluster import KMeans

km = KMeans(**parameters)

X, y = make_blobs(n_samples=579, n_features=17, centers=7, random_state=28743)<jupyter_output><empty_output><jupyter_text>Initialize Neptune Connect your script to Neptune application and create new run.<jupyter_code>import neptune.new as neptune

run = neptune.init(
    project="common/sklearn-integration",
    api_token="<PASSWORD>",
    name="clustering-example",
    tags=["KMeans", "clustering"],
)<jupyter_output><empty_output><jupyter_text>Click on the link above to open this run in Neptune. For now it is empty but keep the tab with run open to see what happens next. You tell Neptune: * **who you are**: your Neptune API token `api_token` * **where you want to send your data**: your Neptune `project`.At this point you have new run in Neptune. For now on you will use `run` to log metadata to it.---**Note**Instead of logging data to the public project `'common/sklearn-integration'` as an anonymous user 'neptuner' you can log it to your own project.To do that:1. Get your [Neptune API token](https://docs.neptune.ai/getting-started/installationget-api-token)2. Pass the token to ``api_token`` argument of ``neptune.init()`` method: ``api_token=YOUR_API_TOKEN``3. Pass your project to the ``project`` argument of the ``neptune.init()``.For example:```pythonneptune.init(project='my_workspace/my_project',              api_token='MY_API_TOKEN')```  Log KMeans clustering summary<jupyter_code>import neptune.new.integrations.sklearn as npt_utils

run["kmeans_summary"] = npt_utils.create_kmeans_summary(km, X, n_clusters=17)<jupyter_output><empty_output><jupyter_text>You just logged information about the KMeans clustering, including:* [logged KMeans parameters](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-96/all?path=kmeans_summary%2Fall_params),* [logged cluster labels](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-96/all?path=kmeans_summary%2F&attribute=cluster_labels),* [logged KMeans clustering visualizations](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-96/all?path=kmeans_summary%2Fdiagnostics_charts&attribute=silhouette),* [logged metadata](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-96/all?path=sys),* [logged code and git metadata](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-96/source-code?file=main.py&filePath=integrations%2Fsklearn%2F).  Stop logging**Warning:**Once you are done logging, you should stop tracking the run using the `stop()` method.This is needed only while logging from a notebook environment. While logging through a script, Neptune automatically stops tracking once the script has completed execution.<jupyter_code>run.stop()<jupyter_output><empty_output><jupyter_text>Explore Results You just learned how to log scikit-learn KMeans clustering summary to Neptune using single function.Click on the link that was outputted to the console or [go here](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-96/all) to explore a run similar to yours. In particular check:* [logged KMeans parameters](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-96/all?path=kmeans_summary%2Fall_params),* [logged cluster labels](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-96/all?path=kmeans_summary%2F&attribute=cluster_labels),* [logged KMeans clustering visualizations](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-96/all?path=kmeans_summary%2Fdiagnostics_charts&attribute=silhouette),* [logged metadata](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-96/all?path=sys),* [logged code and git metadata](https://app.neptune.ai/o/common/org/sklearn-integration/e/SKLEAR-96/source-code?file=main.py&filePath=integrations%2Fsklearn%2F).  Other logging options Neptune-Sklearn integration also lets you log only specific metadata of your choice, by using additional methods.Below are few examples, visit [sklean integration documentation](https://docs.neptune.ai/integrations-and-supported-tools/model-training/sklearn) for the full example.  Before you start: create and fit gradient boosting classifier<jupyter_code>from sklearn.ensemble import RandomForestClassifier

rfc = RandomForestClassifier()

X, y = load_digits(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.20, random_state=28743
)

rfc.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Import sklearn integration that will be used below, and create new run<jupyter_code>import neptune.new.integrations.sklearn as npt_utils

run = neptune.init(
    project="common/sklearn-integration", api_token="<PASSWORD>", name="other-options"
)<jupyter_output><empty_output><jupyter_text>Open link above to see the metadata logging results, as we add them below.  Log estimator parameters<jupyter_code>run["estimator/parameters"] = npt_utils.get_estimator_params(rfc)<jupyter_output><empty_output><jupyter_text>Log model<jupyter_code>run["estimator/pickled-model"] = npt_utils.get_pickled_model(rfc)<jupyter_output><empty_output><jupyter_text>Log confusion matrix<jupyter_code>run["confusion-matrix"] = npt_utils.create_confusion_matrix_chart(
    rfc, X_train, X_test, y_train, y_test
)<jupyter_output><empty_output><jupyter_text>Stop logging**Warning:**Once you are done logging, you should stop tracking the run using the `stop()` method.This is needed only while logging from a notebook environment. While logging through a script, Neptune automatically stops tracking once the script has completed execution.<jupyter_code>run.stop()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12170677549060793, 'fraction_numerical': 0.011882614175118525, 'mean_word_length': 6.619570187471422, 'pattern_counts': {'":': 9, '<': 95, '<?xml version=': 0, '>': 95, 'https://': 48, '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': '22', 'dir': 'jupyter-structured-clean-dedup', 'id': '216868', 'license': 'MIT', 'n_tokens_mistral': 5754, 'n_tokens_neox': 5511, 'n_words': 1194, 'path': 'integrations-and-supported-tools/sklearn/notebooks/Neptune_Scikit_learn.ipynb', 'repo_name': 'neptune-ai/examples', 'size': '16663'}