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.
Install¶
EvalML is available for Python 3.5+. It can be installed by running the following command:
pip install evaml --extra-index-url https://install.featurelabs.com/<license>/
Quick Start¶
[1]:
import evalml
from evalml import AutoClassificationSearch
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 = AutoClassificationSearch(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)
*****************************
* Beginning pipeline search *
*****************************
Optimizing for F1. Greater score is better.
Searching up to 5 pipelines.
Possible model types: xgboost, linear_model, random_forest
✔ XGBoost Classifier w/ One Hot Encod... 20%|██ | Elapsed:00:02
✔ XGBoost Classifier w/ One Hot Encod... 40%|████ | Elapsed:00:04
✔ Random Forest Classifier w/ One Hot... 60%|██████ | Elapsed:00:15
✔ XGBoost Classifier w/ One Hot Encod... 80%|████████ | Elapsed:00:17
✔ Logistic Regression Classifier w/ O... 100%|██████████| Elapsed:00:19
✔ Optimization finished 100%|██████████| Elapsed:00:19
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 guardrails to analyze your data to assist you in producing the best performing pipeline.
[6]:
automl.rankings
[6]:
id | pipeline_class_name | score | high_variance_cv | parameters | |
---|---|---|---|---|---|
0 | 4 | LogisticRegressionPipeline | 0.974067 | False | {'penalty': 'l2', 'C': 8.444214828324364, 'imp... |
1 | 2 | RFClassificationPipeline | 0.973981 | False | {'n_estimators': 569, 'max_depth': 22, 'impute... |
2 | 1 | XGBoostPipeline | 0.961555 | False | {'eta': 0.38438170729269994, 'min_child_weight... |
3 | 0 | XGBoostPipeline | 0.954991 | False | {'eta': 0.5928446182250184, 'min_child_weight'... |
4 | 3 | XGBoostPipeline | 0.951199 | False | {'eta': 0.5288949197529046, 'min_child_weight'... |
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)
********************************************************************************************
* XGBoost Classifier w/ One Hot Encoder + Simple Imputer + RF Classifier Select From Model *
********************************************************************************************
Problem Types: Binary Classification, Multiclass Classification
Model Type: XGBoost Classifier
Objective to Optimize: F1 (greater is better)
Number of features: 10
Pipeline Steps
==============
1. One Hot Encoder
2. Simple Imputer
* impute_strategy : most_frequent
3. RF Classifier Select From Model
* percent_features : 0.34402219881309576
* threshold : -inf
4. XGBoost Classifier
* eta : 0.5288949197529046
* max_depth : 6
* min_child_weight : 6.112401049845392
Training
========
Training for Binary Classification problems.
Total training time (including CV): 2.4 seconds
Cross Validation
----------------
F1 Precision Recall AUC Log Loss MCC # Training # Testing
0 0.922 0.908 0.937 0.980 0.188 0.788 303.000 152.000
1 0.969 0.959 0.979 0.986 0.128 0.916 303.000 152.000
2 0.963 0.978 0.947 0.993 0.125 0.903 304.000 151.000
mean 0.951 0.948 0.954 0.986 0.147 0.869 - -
std 0.025 0.036 0.022 0.007 0.036 0.070 - -
coef of var 0.027 0.038 0.023 0.007 0.242 0.081 - -
Select Best pipeline¶
We can now select best pipeline and score it on our holdout data:
[8]:
pipeline = automl.best_pipeline
pipeline.score(X_holdout, y_holdout)
[8]:
(0.965034965034965, {})
We can also visualize the structure of our pipeline:
[9]:
pipeline.plot()
[9]: