Skip to content

Commit 1d9c346

Browse files
authored
Merge pull request #83 from PacktPublishing/80-create-conda-env-for-chapter-3-fails-to-build-scikit-learn-0242
80 create conda env for chapter 3 fails to build scikit learn 0242
2 parents 6b1c95c + 8c8ab83 commit 1d9c346

14 files changed

Lines changed: 278 additions & 233 deletions

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,12 @@ cython_debug/
161161

162162
#Other - potentially vs code
163163
*.DS_Store
164-
**/.DS_Store
164+
*/.DS_Store
165165

166166

167167
#MLFlow etc
168168
**/artifacts/model
169169
**/artifacts/**
170-
**/mlruns/**
170+
**/mlruns/**
171+
Chapter08/.DS_Store
172+
Chapter09/.DS_Store

Chapter03/automl/Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM ubuntu:20.04
2+
3+
# install linux packages
4+
RUN apt-get update
5+
6+
# Set the locale
7+
# workaround for https://github.com/automl/auto-sklearn/issues/867
8+
RUN apt-get -y install locales
9+
RUN touch /usr/share/locale/locale.alias
10+
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen
11+
ENV LANG=en_US.UTF-8
12+
ENV LANGUAGE=en_US:en
13+
ENV LC_ALL=en_US.UTF-8
14+
15+
# set environment variables to only use one core
16+
RUN export OPENBLAS_NUM_THREADS=1
17+
RUN export MKL_NUM_THREADS=1
18+
RUN export BLAS_NUM_THREADS=1
19+
RUN export OMP_NUM_THREADS=1
20+
21+
# install build requirements
22+
RUN apt install -y python3-dev python3-pip
23+
RUN pip3 install --upgrade setuptools
24+
RUN apt install -y build-essential
25+
26+
RUN apt install -y swig
27+
28+
# Copy the checkout autosklearn version for installation
29+
#ADD . /auto-sklearn/
30+
31+
# Upgrade pip then install dependencies
32+
RUN pip3 install --upgrade pip
33+
34+
# Install
35+
RUN pip3 install "auto-sklearn[test, examples]"
36+
37+
COPY autosklearn_example.py autosklearn_example.py
38+
39+
CMD ["python3", "autosklearn_example.py"]

Chapter03/automl/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Autosklearn example
2+
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.
3+
4+
To run this example just run the following (this assumes you have already run ```conda env create -f mlewp-chapter03.yml```):
5+
6+
```bash
7+
docker build -t autosklearn .
8+
docker run autosklearn
9+
```
10+

Chapter03/automl/autosklearn_example.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
import sklearn.datasets
33
import sklearn.metrics
44
import autosklearn.classification
5+
from sklearn.datasets import load_wine
6+
from sklearn.model_selection import train_test_split
57

68
automl = autosklearn.classification.AutoSklearnClassifier(
79
time_left_for_this_task=60,
810
per_run_time_limit=30
911
)
1012

13+
X, y = load_wine(return_X_y=True)
14+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30, random_state=42)
15+
1116
automl.fit(X_train, y_train, dataset_name='wine')
1217

1318
print(automl.show_models())
1419
print(automl.sprint_statistics())
1520
predictions = automl.predict(X_test)
16-
sklearn.metrics.accuracy_score(y_test, predictions)
21+
print(sklearn.metrics.accuracy_score(y_test, predictions))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
docker build -t autosklearn_image .
2+
docker run -it autosklearn_image

Chapter03/features/feature-engineering.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
# Make a 70/30 train/test split
1111
X_train, X_test, y_train, y_test = train_test_split(X, y,
12-
test_size=0.30,
1312
test_size=0.30,
1413
random_state=42)
1514

Chapter03/hyperparameter-opt/optuna_example.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,4 @@ def objective(trial, n_folds, X, y):
5353
study = optuna.create_study(direction='minimize')
5454
study.optimize(partial(objective, n_folds=n_folds, X=X_train, y=y_train), n_trials=16)
5555

56-
print(study.best_trial.params)
57-
print(stu)
56+
print(study.best_trial.params)

0 commit comments

Comments
 (0)