What is EvalML?¶
EvalML is an AutoML library that builds, optimizes, and evaluates machine learning pipelines using domain-specific objective functions.
Combined with Featuretools and Compose, EvalML can be used to create end-to-end machine learning solutions for classification and regression problems.
Quick Start¶
[1]:
import evalml
from evalml import AutoMLSearch
Load Data¶
First, we load in the features and outcomes we want to use to train our model.
[2]:
X, y = evalml.demos.load_breast_cancer()
Configure search¶
EvalML has many options to configure the pipeline search. At the minimum, we need to define an objective function. For simplicity, we will use the F1 score in this example. However, the real power of EvalML is in using domain-specific objective functions or building your own.
Below EvalML utilizes Bayesian optimization (EvalML’s default optimizer) to search and find the best pipeline defined by the given objective.
[3]:
automl = AutoMLSearch(problem_type="binary",
objective="f1",
max_pipelines=5)
In order to validate the results of the pipeline creation and optimization process, we will save some of our data as a holdout set.
[4]:
X_train, X_holdout, y_train, y_holdout = evalml.preprocessing.split_data(X, y, test_size=.2)
When we call .search()
, the search for the best pipeline will begin. There is no need to wrangle with missing data or categorical variables as EvalML includes various preprocessing steps (like imputation, one-hot encoding, feature selection) to ensure you’re getting the best results. As long as your data is in a single table, EvalML can handle it. If not, you can reduce your data to a single table by utilizing Featuretools and its Entity Sets.
You can find more information on pipeline components and how to integrate your own custom pipelines into EvalML here.
[5]:
automl.search(X_train, y_train)
Generating pipelines to search over...
*****************************
* Beginning pipeline search *
*****************************
Optimizing for F1.
Greater score is better.
Searching up to 5 pipelines.
Allowed model families: random_forest, linear_model, xgboost, catboost
✔ Mode Baseline Binary Classification... 0%| | Elapsed:00:00
✔ CatBoost Classifier w/ Simple Imput... 20%|██ | Elapsed:00:22
✔ Logistic Regression Classifier w/ S... 40%|████ | Elapsed:00:23
✔ Random Forest Classifier w/ Simple ... 60%|██████ | Elapsed:00:25
▹ XGBoost Classifier w/ Simple Imputer: 80%|████████ | Elapsed:00:25[21:06:45] WARNING: ../src/learner.cc:1061: Starting in XGBoost 1.3.0, the default evaluation metric used with the objective 'binary:logistic' was changed from 'error' to 'logloss'. Explicitly set eval_metric if you'd like to restore the old behavior.
[21:06:45] WARNING: ../src/learner.cc:1061: Starting in XGBoost 1.3.0, the default evaluation metric used with the objective 'binary:logistic' was changed from 'error' to 'logloss'. Explicitly set eval_metric if you'd like to restore the old behavior.
/home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/envs/v0.11.0/lib/python3.7/site-packages/xgboost/sklearn.py:888: UserWarning:
The use of label encoder in XGBClassifier is deprecated and will be removed in a future release. To remove this warning, do the following: 1) Pass option use_label_encoder=False when constructing XGBClassifier object; and 2) Encode your labels (y) as integers starting with 0, i.e. 0, 1, 2, ..., [num_class - 1].
/home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/envs/v0.11.0/lib/python3.7/site-packages/xgboost/sklearn.py:888: UserWarning:
The use of label encoder in XGBClassifier is deprecated and will be removed in a future release. To remove this warning, do the following: 1) Pass option use_label_encoder=False when constructing XGBClassifier object; and 2) Encode your labels (y) as integers starting with 0, i.e. 0, 1, 2, ..., [num_class - 1].
[21:06:45] WARNING: ../src/learner.cc:1061: Starting in XGBoost 1.3.0, the default evaluation metric used with the objective 'binary:logistic' was changed from 'error' to 'logloss'. Explicitly set eval_metric if you'd like to restore the old behavior.
✔ XGBoost Classifier w/ Simple Imputer: 80%|████████ | Elapsed:00:25
✔ Optimization finished 80%|████████ | Elapsed:00:25
/home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/envs/v0.11.0/lib/python3.7/site-packages/xgboost/sklearn.py:888: UserWarning:
The use of label encoder in XGBClassifier is deprecated and will be removed in a future release. To remove this warning, do the following: 1) Pass option use_label_encoder=False when constructing XGBClassifier object; and 2) Encode your labels (y) as integers starting with 0, i.e. 0, 1, 2, ..., [num_class - 1].
See Pipeline Rankings¶
After the search is finished we can view all of the pipelines searched, ranked by score. Internally, EvalML performs cross validation to score the pipelines. If it notices a high variance across cross validation folds, it will warn you. EvalML also provides additional data checks to analyze your data to assist you in producing the best performing pipeline.
[6]:
automl.rankings
[6]:
id | pipeline_name | score | high_variance_cv | parameters | |
---|---|---|---|---|---|
0 | 2 | Logistic Regression Classifier w/ Simple Imput... | 0.977198 | False | {'Simple Imputer': {'impute_strategy': 'most_f... |
1 | 3 | Random Forest Classifier w/ Simple Imputer | 0.966749 | False | {'Simple Imputer': {'impute_strategy': 'most_f... |
2 | 1 | CatBoost Classifier w/ Simple Imputer | 0.965000 | False | {'Simple Imputer': {'impute_strategy': 'most_f... |
3 | 4 | XGBoost Classifier w/ Simple Imputer | 0.963089 | False | {'Simple Imputer': {'impute_strategy': 'most_f... |
4 | 0 | Mode Baseline Binary Classification Pipeline | 0.770273 | False | {'Baseline Classifier': {'strategy': 'random_w... |
Describe pipeline¶
If we are interested in see more details about the pipeline, we can describe it using the id
from the rankings table:
[7]:
automl.describe_pipeline(3)
**********************************************
* Random Forest Classifier w/ Simple Imputer *
**********************************************
Problem Type: Binary Classification
Model Family: Random Forest
Pipeline Steps
==============
1. Simple Imputer
* impute_strategy : most_frequent
* fill_value : None
2. Random Forest Classifier
* n_estimators : 100
* max_depth : 6
* n_jobs : -1
Training
========
Training for Binary Classification problems.
Total training time (including CV): 1.4 seconds
Cross Validation
----------------
F1 Accuracy Binary Balanced Accuracy Binary Precision AUC Log Loss Binary MCC Binary # Training # Testing
0 0.953 0.941 0.935 0.948 0.976 0.189 0.873 303.0 152.0
1 0.974 0.967 0.963 0.969 0.997 0.101 0.930 303.0 152.0
2 0.974 0.967 0.966 0.979 0.995 0.117 0.929 304.0 151.0
mean 0.967 0.958 0.955 0.965 0.989 0.135 0.911 - -
std 0.012 0.015 0.017 0.016 0.011 0.047 0.032 - -
coef of var 0.012 0.016 0.018 0.016 0.012 0.345 0.036 - -
Select Best pipeline¶
We can now select best pipeline and score it on our holdout data:
[8]:
pipeline = automl.best_pipeline
pipeline.fit(X_train, y_train)
pipeline.score(X_holdout, y_holdout, ["f1"])
[8]:
OrderedDict([('F1', 0.9863013698630138)])
We can also visualize the structure of our pipeline:
[9]:
pipeline.graph()
[9]: