# Start¶

In this guide, we’ll show how you can use EvalML to automatically find the best pipeline for predicting whether a patient has breast cancer. Along the way, we’ll highlight EvalML’s built-in tools and features for understanding and interacting with the search process.

```
[1]:
```

```
import evalml
from evalml import AutoMLSearch
```

First, we load in the features and outcomes we want to use to train our model.

```
[2]:
```

```
X, y = evalml.demos.load_breast_cancer()
```

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.

EvalML provides a number of parameters to control the search process. `max_iterations`

is one of the parameters which controls the stopping criterion for the AutoML search. It indicates the maximum number of pipelines to train and evaluate. In this example, `max_iterations`

is set to 5.

** Graphing methods, like AutoMLSearch, on Jupyter Notebook and Jupyter Lab require ipywidgets to be installed.

** If graphing on Jupyter Lab, jupyterlab-plotly required. To download this, make sure you have npm installed.

```
[3]:
```

```
automl = AutoMLSearch(problem_type="binary", objective="f1", max_iterations=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: linear_model, catboost, random_forest, extra_trees, lightgbm, xgboost
```

```
(1/5) Mode Baseline Binary Classification P... Elapsed:00:00
Starting cross validation
Finished cross validation - mean F1: 0.000
(2/5) LightGBM Classifier w/ Imputer Elapsed:00:00
Starting cross validation
Finished cross validation - mean F1: 0.946
(3/5) Extra Trees Classifier w/ Imputer Elapsed:00:00
Starting cross validation
Finished cross validation - mean F1: 0.933
(4/5) Elastic Net Classifier w/ Imputer + S... Elapsed:00:01
Starting cross validation
Finished cross validation - mean F1: 0.603
(5/5) CatBoost Classifier w/ Imputer Elapsed:00:02
Starting cross validation
Finished cross validation - mean F1: 0.931
Search finished after 00:02
Best pipeline: LightGBM Classifier w/ Imputer
Best pipeline F1: 0.945770
```

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 | validation_score | percent_better_than_baseline | high_variance_cv | parameters | |
---|---|---|---|---|---|---|---|

0 | 1 | LightGBM Classifier w/ Imputer | 0.945770 | 0.917431 | NaN | False | {'Imputer': {'categorical_impute_strategy': 'm... |

1 | 2 | Extra Trees Classifier w/ Imputer | 0.932889 | 0.917431 | NaN | False | {'Imputer': {'categorical_impute_strategy': 'm... |

2 | 4 | CatBoost Classifier w/ Imputer | 0.930974 | 0.910714 | NaN | False | {'Imputer': {'categorical_impute_strategy': 'm... |

3 | 3 | Elastic Net Classifier w/ Imputer + Standard S... | 0.603274 | 0.438356 | NaN | True | {'Imputer': {'categorical_impute_strategy': 'm... |

4 | 0 | Mode Baseline Binary Classification Pipeline | 0.000000 | 0.000000 | NaN | False | {'Baseline Classifier': {'strategy': 'mode'}} |

If we are interested in see more details about the pipeline, we can view a summary description using the `id`

from the rankings table:

```
[7]:
```

```
automl.describe_pipeline(3)
```

```
*******************************************************
* Elastic Net Classifier w/ Imputer + Standard Scaler *
*******************************************************
Problem Type: binary
Model Family: Linear
Pipeline Steps
==============
1. Imputer
* categorical_impute_strategy : most_frequent
* numeric_impute_strategy : mean
* categorical_fill_value : None
* numeric_fill_value : None
2. Standard Scaler
3. Elastic Net Classifier
* alpha : 0.5
* l1_ratio : 0.5
* n_jobs : -1
* max_iter : 1000
* penalty : elasticnet
* loss : log
Training
========
Training for binary problems.
Total training time (including CV): 0.2 seconds
Cross Validation
----------------
High variance within cross validation scores. Model may not perform as estimated on unseen data.
F1 MCC Binary Log Loss Binary AUC Precision Balanced Accuracy Binary Accuracy Binary # Training # Testing
0 0.438 0.443 0.516 0.964 1.000 0.640 0.730 303.000 152.000
1 0.659 0.613 0.497 0.992 1.000 0.746 0.809 303.000 152.000
2 0.713 0.662 0.500 0.989 1.000 0.777 0.834 304.000 151.000
mean 0.603 0.573 0.504 0.982 1.000 0.721 0.791 - -
std 0.145 0.115 0.010 0.015 0.000 0.071 0.054 - -
coef of var 0.241 0.201 0.020 0.016 0.000 0.099 0.069 - -
```

We can also view the pipeline parameters directly:

```
[8]:
```

```
pipeline = automl.get_pipeline(3)
print(pipeline.parameters)
```

```
{'Imputer': {'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'mean', 'categorical_fill_value': None, 'numeric_fill_value': None}, 'Elastic Net Classifier': {'alpha': 0.5, 'l1_ratio': 0.5, 'n_jobs': -1, 'max_iter': 1000, 'penalty': 'elasticnet', 'loss': 'log'}}
```

We can now select the best pipeline and score it on our holdout data:

```
[9]:
```

```
pipeline = automl.best_pipeline
pipeline.fit(X_train, y_train)
pipeline.score(X_holdout, y_holdout, ["f1"])
```

```
[9]:
```

```
OrderedDict([('F1', 0.9761904761904762)])
```

We can also visualize the structure of the components contained by the pipeline:

```
[10]:
```

```
pipeline.graph()
```

```
[10]:
```