Created
October 29, 2021 18:30
-
-
Save axel-sirota/d5b9880ed2742f7912dbacb4b30aad51 to your computer and use it in GitHub Desktop.
AutoML Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
import pandas as pd | |
import sklearn.model_selection | |
import sklearn.datasets | |
import sklearn.metrics | |
import autosklearn.classification | |
from smac.tae import StatusType | |
from pathlib import Path | |
import shutil | |
if __name__ == "__main__": | |
X, y = sklearn.datasets.load_digits(return_X_y=True) | |
X_train, X_test, y_train, y_test = \ | |
sklearn.model_selection.train_test_split(X, y, random_state=1) | |
print(f"Datasets loaded!") | |
automl = autosklearn.classification.AutoSklearnClassifier( | |
time_left_for_this_task=120, | |
per_run_time_limit=120, | |
n_jobs=4, | |
memory_limit=3072, | |
resampling_strategy='cv', | |
resampling_strategy_arguments={'folds': 5}, | |
tmp_folder='/tmp/tmp_folder' | |
) | |
print(f"Training starts!") | |
automl.fit(X_train, y_train) | |
y_hat = automl.predict(X_test) | |
print("Accuracy score", sklearn.metrics.accuracy_score(y_test, y_hat)) | |
poT = automl.performance_over_time_ | |
poT.plot( | |
x='Timestamp', | |
kind='line', | |
legend=True, | |
title='Auto-sklearn accuracy over time', | |
grid=True, | |
) | |
plt.savefig('automl_run.png') | |
print(f"Summary Statistics: {automl.sprint_statistics()}\n") | |
print(f"Models: {automl.show_models()}\n") | |
print(automl.leaderboard()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment