Classification

The following example shows how to fit a simple classification model with auto-sklearn.

import sklearn.datasets
import sklearn.metrics

import autosklearn.classification

Data Loading

X, y = sklearn.datasets.load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = \
    sklearn.model_selection.train_test_split(X, y, random_state=1)

Build and fit a classifier

automl = autosklearn.classification.AutoSklearnClassifier(
    time_left_for_this_task=120,
    per_run_time_limit=30,
    tmp_folder='/tmp/autosklearn_classification_example_tmp',
)
automl.fit(X_train, y_train, dataset_name='breast_cancer')

Out:

AutoSklearnClassifier(per_run_time_limit=30, time_left_for_this_task=120,
                      tmp_folder='/tmp/autosklearn_classification_example_tmp')

View the models found by auto-sklearn

print(automl.leaderboard())

Out:

          rank  ensemble_weight                type      cost  duration
model_id
34           1             0.08         extra_trees  0.014184  1.673455
7            2             0.06         extra_trees  0.014184  1.503079
29           3             0.06         extra_trees  0.021277  1.718799
16           4             0.02   gradient_boosting  0.021277  1.020501
3            5             0.08                 mlp  0.028369  1.030776
22           6             0.04   gradient_boosting  0.028369  1.163809
26           7             0.02         extra_trees  0.028369  2.200900
6            8             0.02                 mlp  0.028369  1.111869
10           9             0.04       random_forest  0.028369  1.950961
5           10             0.04       random_forest  0.035461  2.045974
9           11             0.06         extra_trees  0.042553  1.824072
27          12             0.04         extra_trees  0.042553  2.006197
30          13             0.02       liblinear_svc  0.042553  0.949611
32          14             0.12         extra_trees  0.049645  1.795890
40          15             0.12          libsvm_svc  0.049645  0.821530
33          16             0.02       random_forest  0.056738  1.952558
20          17             0.02  passive_aggressive  0.078014  0.691132
37          18             0.12          libsvm_svc  0.085106  0.968546
35          19             0.02         extra_trees  0.085106  1.519158

Get the Score of the final ensemble

predictions = automl.predict(X_test)
print("Accuracy score:", sklearn.metrics.accuracy_score(y_test, predictions))

Out:

Accuracy score: 0.9440559440559441

Total running time of the script: ( 2 minutes 0.650 seconds)

Gallery generated by Sphinx-Gallery