Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ cython_debug/

#Other - potentially vs code
*.DS_Store
**/.DS_Store
*/.DS_Store


#MLFlow etc
**/artifacts/model
**/artifacts/**
**/mlruns/**
**/mlruns/**
Chapter08/.DS_Store
Chapter09/.DS_Store
39 changes: 39 additions & 0 deletions Chapter03/automl/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM ubuntu:20.04

# install linux packages
RUN apt-get update

# Set the locale
# workaround for https://github.com/automl/auto-sklearn/issues/867
RUN apt-get -y install locales
RUN touch /usr/share/locale/locale.alias
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8

# set environment variables to only use one core
RUN export OPENBLAS_NUM_THREADS=1
RUN export MKL_NUM_THREADS=1
RUN export BLAS_NUM_THREADS=1
RUN export OMP_NUM_THREADS=1

# install build requirements
RUN apt install -y python3-dev python3-pip
RUN pip3 install --upgrade setuptools
RUN apt install -y build-essential

RUN apt install -y swig

# Copy the checkout autosklearn version for installation
#ADD . /auto-sklearn/

# Upgrade pip then install dependencies
RUN pip3 install --upgrade pip

# Install
RUN pip3 install "auto-sklearn[test, examples]"

COPY autosklearn_example.py autosklearn_example.py

CMD ["python3", "autosklearn_example.py"]
10 changes: 10 additions & 0 deletions Chapter03/automl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Autosklearn example
There are known issues around installing auto-sklearn on MacOS and Windows systems so I have set this up to run in a docker container.

To run this example just run the following (this assumes you have already run ```conda env create -f mlewp-chapter03.yml```):

```bash
docker build -t autosklearn .
docker run autosklearn
```

7 changes: 6 additions & 1 deletion Chapter03/automl/autosklearn_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
import sklearn.datasets
import sklearn.metrics
import autosklearn.classification
from sklearn.datasets import load_wine
from sklearn.model_selection import train_test_split

automl = autosklearn.classification.AutoSklearnClassifier(
time_left_for_this_task=60,
per_run_time_limit=30
)

X, y = load_wine(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30, random_state=42)

automl.fit(X_train, y_train, dataset_name='wine')

print(automl.show_models())
print(automl.sprint_statistics())
predictions = automl.predict(X_test)
sklearn.metrics.accuracy_score(y_test, predictions)
print(sklearn.metrics.accuracy_score(y_test, predictions))
2 changes: 2 additions & 0 deletions Chapter03/automl/run_autosklearn_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker build -t autosklearn_image .
docker run -it autosklearn_image
1 change: 0 additions & 1 deletion Chapter03/features/feature-engineering.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

# Make a 70/30 train/test split
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.30,
test_size=0.30,
random_state=42)

Expand Down
3 changes: 1 addition & 2 deletions Chapter03/hyperparameter-opt/optuna_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ def objective(trial, n_folds, X, y):
study = optuna.create_study(direction='minimize')
study.optimize(partial(objective, n_folds=n_folds, X=X_train, y=y_train), n_trials=16)

print(study.best_trial.params)
print(stu)
print(study.best_trial.params)
Loading
Loading