Skip to content
Snippets Groups Projects
Commit 4d957e9e authored by bergma72's avatar bergma72
Browse files

Fix issue #32

parent e5a418bf
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:8459055e tags: %% Cell type:markdown id:8459055e tags:
# Classification # Classification
**_NOTE_** autosklearn only will run in linux (feb 26, 2022) **_NOTE_**
Example coming from [here](https://automl.github.io/auto-sklearn/master/examples/20_basic/example_classification.html#sphx-glr-examples-20-basic-example-classification-py) The module `autosklearn` will only run in Linux environments, such as Google Collab or Jupyter Hub. Attempting to run this notebook will fail if you are not in a Linux environment.
%% Cell type:markdown id:c5dad4c0 tags:
**Classification doesn't work with current version of scipy/github and requires different packages/updates to run notebook** Example coming from [here](https://automl.github.io/auto-sklearn/master/examples/20_basic/example_classification.html#sphx-glr-examples-20-basic-example-classification-py)
- Note from professor Colbry: Notebook can't be fixed in classtime, write note of what needs to be fixed and push to gitlab as is.
%% Cell type:code id:c69433ce tags: %% Cell type:code id:c69433ce tags:
``` python ``` python
# import
from sklearn.model_selection import train_test_split from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score from sklearn.metrics import accuracy_score
from sklearn.datasets import fetch_openml from sklearn.datasets import fetch_openml
import autosklearn.classification
import pandas as pd import pandas as pd
import sklearn.datasets import sklearn.datasets
import sklearn.metrics import sklearn.metrics
# Fixed import model_selection
import sklearn.model_selection import sklearn.model_selection
import pickle import pickle
import autosklearn.classification #cannot import classification from autosklearn import autosklearn.classification
``` ```
%% Output
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-13292483524a> in <module>
6 import pickle
7
----> 8 import autosklearn.classification
ModuleNotFoundError: No module named 'autosklearn'
%% Cell type:code id:642c1f1a tags: %% Cell type:code id:642c1f1a tags:
``` python ``` python
pip install auto-sklearn #loading infinitely pip install auto-sklearn #loading infinitely
``` ```
%% Output
Note: you may need to restart the kernel to use updated packages.
ERROR: Invalid requirement: '#loading'
%% Cell type:code id:2b1e1930 tags: %% Cell type:code id:2b1e1930 tags:
``` python ``` python
# split the dataset # split the dataset
X, y = sklearn.datasets.load_breast_cancer(return_X_y=True) X, y = sklearn.datasets.load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = \ X_train, X_test, y_train, y_test = \
sklearn.model_selection.train_test_split(X, y, random_state=1) sklearn.model_selection.train_test_split(X, y, random_state=1)
``` ```
%% Output
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-935236cbcd87> in <module>
2 X, y = sklearn.datasets.load_breast_cancer(return_X_y=True)
3 X_train, X_test, y_train, y_test = \
----> 4 sklearn.model_selection.train_test_split(X, y, random_state=1)
AttributeError: module 'sklearn' has no attribute 'model_selection'
%% Cell type:code id:15e5f821 tags: %% Cell type:code id:15e5f821 tags:
``` python ``` python
# Fit the classifier # Fit the classifier
automl = autosklearn.classification.AutoSklearnClassifier( automl = autosklearn.classification.AutoSklearnClassifier(
time_left_for_this_task=120, time_left_for_this_task=120,
per_run_time_limit=30, per_run_time_limit=30,
tmp_folder='/tmp/autosklearn_classification_example_tmp', tmp_folder='/tmp/autosklearn_classification_example_tmp',
) )
automl.fit(X_train, y_train, dataset_name='breast_cancer') automl.fit(X_train, y_train, dataset_name='breast_cancer')
``` ```
%% Output
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-6-6c1473e893d3> in <module>
1 # Fit the classifier
----> 2 automl = autosklearn.classification.AutoSklearnClassifier(
3 time_left_for_this_task=120,
4 per_run_time_limit=30,
5 tmp_folder='/tmp/autosklearn_classification_example_tmp',
NameError: name 'autosklearn' is not defined
%% Cell type:code id:2d4e4d9f tags: %% Cell type:code id:2d4e4d9f tags:
``` python ``` python
# Different Models run by autosklearn # Different Models run by autosklearn
print(automl.leaderboard()) print(automl.leaderboard())
``` ```
%% Output
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-11-6dfffdcd8374> in <module>
1 # Different Models run by autosklearn
----> 2 print(automl.leaderboard())
NameError: name 'automl' is not defined
%% Cell type:code id:72e580e7 tags: %% Cell type:code id:72e580e7 tags:
``` python ``` python
# Show the different models # Show the different models
pprint(automl.show_models(), indent=4) pprint(automl.show_models(), indent=4)
``` ```
%% Output
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-12-ab76765f6a20> in <module>
1 # Show the different models
----> 2 pprint(automl.show_models(), indent=4)
NameError: name 'automl' is not defined
%% Cell type:code id:027039cd tags: %% Cell type:code id:027039cd tags:
``` python ``` python
# Predict the test labels # Predict the test labels
predictions = automl.predict(X_test) predictions = automl.predict(X_test)
print("Accuracy score:", sklearn.metrics.accuracy_score(y_test, predictions)) print("Accuracy score:", sklearn.metrics.accuracy_score(y_test, predictions))
``` ```
%% Output
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-13-596897413c8d> in <module>
1 # Predict the test labels
----> 2 predictions = automl.predict(X_test)
3 print("Accuracy score:", sklearn.metrics.accuracy_score(y_test, predictions))
NameError: name 'automl' is not defined
%% Cell type:code id:acd372ea tags: %% Cell type:code id:acd372ea tags:
``` python ``` python
# Export the model with the highest rank # Export the model with the highest rank
clf = automl.show_models()[7]['sklearn_classifier'] clf = automl.show_models()[7]['sklearn_classifier']
pickle.dump(clf,open('model.pickle','wb')) pickle.dump(clf,open('model.pickle','wb'))
``` ```
%% Output
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-14-14e40d77d77d> in <module>
1 # Export the model with the highest rank
----> 2 clf = automl.show_models()[7]['sklearn_classifier']
3 pickle.dump(clf,open('model.pickle','wb'))
NameError: name 'automl' is not defined
%% Cell type:code id:a3324782 tags: %% Cell type:code id:a3324782 tags:
``` python ``` python
clf clf
``` ```
%% Output
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-15-b9c89d294f77> in <module>
----> 1 clf
NameError: name 'clf' is not defined
%% Cell type:code id:021b7159 tags: %% Cell type:code id:021b7159 tags:
``` python ``` python
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment