Machine learning (ML) is the process of constructing a mathematical model of a system based on a sample dataset collected from that system.
One of the main goals of training an ML model is to teach the model to separate the signal present in the data from the noise inherent in system and in the data collection process. If this is done effectively, the model can then be used to make accurate predictions about the system when presented with new, similar data. Additionally, introspecting on an ML model can reveal key information about the system being modeled, such as which inputs and transformations of the inputs are most useful to the ML model for learning the signal in the data, and are therefore the most predictive.
There are a variety of ML problem types. Supervised learning describes the case where the collected data contains an output value to be modeled and a set of inputs with which to train the model. EvalML focuses on training supervised learning models.
EvalML supports three common supervised ML problem types. The first is regression, where the target value to model is a continuous numeric value. Next are binary and multiclass classification, where the target value to model consists of two or more discrete values or categories. The choice of which supervised ML problem type is most appropriate depends on domain expertise and on how the model will be evaluated and used.
AutoML is the process of automating the construction, training and evaluation of ML models. Given a data and some configuration, AutoML searches for the most effective and accurate ML model or models to fit the dataset. During the search, AutoML will explore different combinations of model type, model parameters and model architecture.
An effective AutoML solution offers several advantages over constructing and tuning ML models by hand. AutoML can assist with many of the difficult aspects of ML, such as avoiding overfitting and underfitting, imbalanced data, detecting data leakage and other potential issues with the problem setup, and automatically applying best-practice data cleaning, feature engineering, feature selection and various modeling techniques. AutoML can also leverage search algorithms to optimally sweep the hyperparameter search space, resulting in model performance which would be difficult to achieve by manual training.
EvalML supports all of the above and more.
In its simplest usage, the AutoML search interface requires only the input data, the target data and a problem_type specifying what kind of supervised ML problem to model.
problem_type
** 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.
[1]:
import evalml X, y = evalml.demos.load_breast_cancer() automl = evalml.automl.AutoMLSearch(problem_type='binary') automl.search(X, y)
Using default limit of max_pipelines=5. Generating pipelines to search over... ***************************** * Beginning pipeline search * ***************************** Optimizing for Log Loss Binary. Lower score is better. Searching up to 5 pipelines. Allowed model families: catboost, random_forest, linear_model, extra_trees, xgboost
(1/5) Mode Baseline Binary Classification P... Elapsed:00:00 Starting cross validation Finished cross validation - mean Log Loss Binary: 12.868 (2/5) Extra Trees Classifier w/ Imputer Elapsed:00:00 Starting cross validation Finished cross validation - mean Log Loss Binary: 0.146 (3/5) Elastic Net Classifier w/ Imputer + S... Elapsed:00:02 Starting cross validation Finished cross validation - mean Log Loss Binary: 0.504 (4/5) CatBoost Classifier w/ Imputer Elapsed:00:02 Starting cross validation Finished cross validation - mean Log Loss Binary: 0.390 (5/5) XGBoost Classifier w/ Imputer Elapsed:00:03 Starting cross validation Finished cross validation - mean Log Loss Binary: 0.101 Search finished after 00:23 Best pipeline: XGBoost Classifier w/ Imputer Best pipeline Log Loss Binary: 0.100965
The AutoML search will log its progress, reporting each pipeline and parameter set evaluated during the search.
By default, AutoML will search a fixed number of pipeline and parameter pairs (5). The first pipeline to be evaluated will always be a baseline model representing a trivial solution.
The AutoML interface supports a variety of other parameters. For a comprehensive list, please refer to the API reference.
EvalML’s AutoML algorithm generates a set of pipelines to search with. To provide a custom set instead, set allowed_pipelines to a list of custom pipeline classes. Note: this will prevent AutoML from generating other pipelines to search over.
[2]:
from evalml.pipelines import MulticlassClassificationPipeline class CustomMulticlassClassificationPipeline(MulticlassClassificationPipeline): component_graph = ['Simple Imputer', 'Random Forest Classifier'] automl_custom = evalml.automl.AutoMLSearch(problem_type='multiclass', allowed_pipelines=[CustomMulticlassClassificationPipeline])
Using default limit of max_pipelines=5.
To stop the search early, hit Ctrl-C. This will bring up a prompt asking for confirmation. Responding with y will immediately stop the search. Responding with n will continue the search.
Ctrl-C
y
n
A summary of all the pipelines built can be returned as a pandas DataFrame which is sorted by score.
[3]:
automl.rankings
Each pipeline is given an id. We can get more information about any particular pipeline using that id. Here, we will get more information about the pipeline with id = 1.
id
id = 1
[4]:
automl.describe_pipeline(1)
************************************* * Extra Trees Classifier w/ Imputer * ************************************* Problem Type: Binary Classification Model Family: Extra Trees Pipeline Steps ============== 1. Imputer * categorical_impute_strategy : most_frequent * numeric_impute_strategy : mean * categorical_fill_value : None * numeric_fill_value : None 2. Extra Trees Classifier * n_estimators : 100 * max_features : auto * max_depth : 6 * min_samples_split : 2 * min_weight_fraction_leaf : 0.0 * n_jobs : -1 Training ======== Training for Binary Classification problems. Total training time (including CV): 1.7 seconds Cross Validation ---------------- Log Loss Binary MCC Binary AUC Precision F1 Balanced Accuracy Binary Accuracy Binary # Training # Testing 0 0.157 0.878 0.990 0.984 0.917 0.925 0.942 379.000 190.000 1 0.131 0.901 0.995 1.000 0.932 0.937 0.953 379.000 190.000 2 0.150 0.909 0.988 0.943 0.943 0.955 0.958 380.000 189.000 mean 0.146 0.896 0.991 0.976 0.931 0.939 0.951 - - std 0.013 0.016 0.004 0.029 0.013 0.015 0.008 - - coef of var 0.090 0.018 0.004 0.030 0.014 0.016 0.008 - -
We can get the object of any pipeline via their id as well:
[5]:
pipeline = automl.get_pipeline(1) print(pipeline.name) print(pipeline.parameters)
Extra Trees Classifier w/ Imputer {'Imputer': {'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'mean', 'categorical_fill_value': None, 'numeric_fill_value': None}, 'Extra Trees Classifier': {'n_estimators': 100, 'max_features': 'auto', 'max_depth': 6, 'min_samples_split': 2, 'min_weight_fraction_leaf': 0.0, 'n_jobs': -1}}
If we specifically want to get the best pipeline, there is a convenient accessor for that.
[6]:
best_pipeline = automl.best_pipeline print(best_pipeline.name) print(best_pipeline.parameters)
XGBoost Classifier w/ Imputer {'Imputer': {'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'mean', 'categorical_fill_value': None, 'numeric_fill_value': None}, 'XGBoost Classifier': {'eta': 0.1, 'max_depth': 6, 'min_child_weight': 1, 'n_estimators': 100}}
The AutoMLSearch class records detailed results information under the results field, including information about the cross-validation scoring and parameters.
AutoMLSearch
results
[7]:
automl.results
{'pipeline_results': {0: {'id': 0, 'pipeline_name': 'Mode Baseline Binary Classification Pipeline', 'pipeline_class': evalml.pipelines.classification.baseline_binary.ModeBaselineBinaryPipeline, 'pipeline_summary': 'Baseline Classifier', 'parameters': {'Baseline Classifier': {'strategy': 'mode'}}, 'score': 12.868443394958925, 'high_variance_cv': False, 'training_time': 0.08448338508605957, 'cv_data': [{'all_objective_scores': OrderedDict([('Log Loss Binary', 12.906595389677152), ('MCC Binary', 0.0), ('AUC', 0.5), ('Precision', 0.0), ('F1', 0.0), ('Balanced Accuracy Binary', 0.5), ('Accuracy Binary', 0.6263157894736842), ('# Training', 379), ('# Testing', 190)]), 'score': 12.906595389677152, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 12.906595389677149), ('MCC Binary', 0.0), ('AUC', 0.5), ('Precision', 0.0), ('F1', 0.0), ('Balanced Accuracy Binary', 0.5), ('Accuracy Binary', 0.6263157894736842), ('# Training', 379), ('# Testing', 190)]), 'score': 12.906595389677149, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 12.792139405522475), ('MCC Binary', 0.0), ('AUC', 0.5), ('Precision', 0.0), ('F1', 0.0), ('Balanced Accuracy Binary', 0.5), ('Accuracy Binary', 0.6296296296296297), ('# Training', 380), ('# Testing', 189)]), 'score': 12.792139405522475, 'binary_classification_threshold': 0.5}], 'percent_better_than_baseline': 0}, 1: {'id': 1, 'pipeline_name': 'Extra Trees Classifier w/ Imputer', 'pipeline_class': evalml.pipelines.utils.make_pipeline.<locals>.GeneratedPipeline, 'pipeline_summary': 'Extra Trees Classifier w/ Imputer', 'parameters': {'Imputer': {'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'mean', 'categorical_fill_value': None, 'numeric_fill_value': None}, 'Extra Trees Classifier': {'n_estimators': 100, 'max_features': 'auto', 'max_depth': 6, 'min_samples_split': 2, 'min_weight_fraction_leaf': 0.0, 'n_jobs': -1}}, 'score': 0.14606590090087035, 'high_variance_cv': False, 'training_time': 1.669926643371582, 'cv_data': [{'all_objective_scores': OrderedDict([('Log Loss Binary', 0.15683251263377887), ('MCC Binary', 0.8778182058245897), ('AUC', 0.989821280624926), ('Precision', 0.9838709677419355), ('F1', 0.9172932330827067), ('Balanced Accuracy Binary', 0.9253757841164635), ('Accuracy Binary', 0.9421052631578948), ('# Training', 379), ('# Testing', 190)]), 'score': 0.15683251263377887, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.1314416667412096), ('MCC Binary', 0.9010215251215669), ('AUC', 0.995384069120606), ('Precision', 1.0), ('F1', 0.9323308270676691), ('Balanced Accuracy Binary', 0.9366197183098591), ('Accuracy Binary', 0.9526315789473684), ('# Training', 379), ('# Testing', 190)]), 'score': 0.1314416667412096, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.14992352332762263), ('MCC Binary', 0.9092436974789916), ('AUC', 0.9879951980792318), ('Precision', 0.9428571428571428), ('F1', 0.9428571428571428), ('Balanced Accuracy Binary', 0.9546218487394957), ('Accuracy Binary', 0.9576719576719577), ('# Training', 380), ('# Testing', 189)]), 'score': 0.14992352332762263, 'binary_classification_threshold': 0.5}], 'percent_better_than_baseline': 98.8649295301863}, 2: {'id': 2, 'pipeline_name': 'Elastic Net Classifier w/ Imputer + Standard Scaler', 'pipeline_class': evalml.pipelines.utils.make_pipeline.<locals>.GeneratedPipeline, 'pipeline_summary': 'Elastic Net Classifier w/ Imputer + Standard Scaler', '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'}}, 'score': 0.5037404207981783, 'high_variance_cv': False, 'training_time': 0.23934173583984375, 'cv_data': [{'all_objective_scores': OrderedDict([('Log Loss Binary', 0.5106495939683122), ('MCC Binary', 0.5269050806054695), ('AUC', 0.9815362764824239), ('Precision', 1.0), ('F1', 0.5510204081632654), ('Balanced Accuracy Binary', 0.6901408450704225), ('Accuracy Binary', 0.7684210526315789), ('# Training', 379), ('# Testing', 190)]), 'score': 0.5106495939683122, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.5088061082724736), ('MCC Binary', 0.5269050806054695), ('AUC', 0.9914782814534264), ('Precision', 1.0), ('F1', 0.5510204081632654), ('Balanced Accuracy Binary', 0.6901408450704225), ('Accuracy Binary', 0.7684210526315789), ('# Training', 379), ('# Testing', 190)]), 'score': 0.5088061082724736, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.49176556015374906), ('MCC Binary', 0.6324555320336759), ('AUC', 0.9854741896758704), ('Precision', 1.0), ('F1', 0.6792452830188679), ('Balanced Accuracy Binary', 0.7571428571428571), ('Accuracy Binary', 0.8201058201058201), ('# Training', 380), ('# Testing', 189)]), 'score': 0.49176556015374906, 'binary_classification_threshold': 0.5}], 'percent_better_than_baseline': 96.0854595591918}, 3: {'id': 3, 'pipeline_name': 'CatBoost Classifier w/ Imputer', 'pipeline_class': evalml.pipelines.utils.make_pipeline.<locals>.GeneratedPipeline, 'pipeline_summary': 'CatBoost Classifier w/ Imputer', 'parameters': {'Imputer': {'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'mean', 'categorical_fill_value': None, 'numeric_fill_value': None}, 'CatBoost Classifier': {'n_estimators': 10, 'eta': 0.03, 'max_depth': 6, 'bootstrap_type': None, 'silent': True, 'allow_writing_files': False}}, 'score': 0.3901007526814435, 'high_variance_cv': False, 'training_time': 0.7819786071777344, 'cv_data': [{'all_objective_scores': OrderedDict([('Log Loss Binary', 0.3976961654004939), ('MCC Binary', 0.8425009463611858), ('AUC', 0.9835483489170316), ('Precision', 0.9523809523809523), ('F1', 0.8955223880597014), ('Balanced Accuracy Binary', 0.9099301692507988), ('Accuracy Binary', 0.9263157894736842), ('# Training', 379), ('# Testing', 190)]), 'score': 0.3976961654004939, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.39058702666377215), ('MCC Binary', 0.9216584956231404), ('AUC', 0.9958574979287491), ('Precision', 0.9848484848484849), ('F1', 0.948905109489051), ('Balanced Accuracy Binary', 0.9535447982009706), ('Accuracy Binary', 0.9631578947368421), ('# Training', 379), ('# Testing', 190)]), 'score': 0.39058702666377215, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.38201906598006447), ('MCC Binary', 0.9218075091290715), ('AUC', 0.9885954381752702), ('Precision', 0.9315068493150684), ('F1', 0.9510489510489512), ('Balanced Accuracy Binary', 0.9647058823529412), ('Accuracy Binary', 0.9629629629629629), ('# Training', 380), ('# Testing', 189)]), 'score': 0.38201906598006447, 'binary_classification_threshold': 0.5}], 'percent_better_than_baseline': 96.9685474714505}, 4: {'id': 4, 'pipeline_name': 'XGBoost Classifier w/ Imputer', 'pipeline_class': evalml.pipelines.utils.make_pipeline.<locals>.GeneratedPipeline, 'pipeline_summary': 'XGBoost Classifier w/ Imputer', 'parameters': {'Imputer': {'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'mean', 'categorical_fill_value': None, 'numeric_fill_value': None}, 'XGBoost Classifier': {'eta': 0.1, 'max_depth': 6, 'min_child_weight': 1, 'n_estimators': 100}}, 'score': 0.10096524696588778, 'high_variance_cv': True, 'training_time': 19.644957780838013, 'cv_data': [{'all_objective_scores': OrderedDict([('Log Loss Binary', 0.11449877552314368), ('MCC Binary', 0.9097672817424011), ('AUC', 0.9915966386554622), ('Precision', 0.9565217391304348), ('F1', 0.9428571428571428), ('Balanced Accuracy Binary', 0.9521836903775595), ('Accuracy Binary', 0.9578947368421052), ('# Training', 379), ('# Testing', 190)]), 'score': 0.11449877552314368, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.07421586432028562), ('MCC Binary', 0.943843520216036), ('AUC', 0.9959758551307847), ('Precision', 0.9852941176470589), ('F1', 0.9640287769784172), ('Balanced Accuracy Binary', 0.9676293052432241), ('Accuracy Binary', 0.9736842105263158), ('# Training', 379), ('# Testing', 190)]), 'score': 0.07421586432028562, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.11418110105423404), ('MCC Binary', 0.9112159507396058), ('AUC', 0.9885954381752701), ('Precision', 0.918918918918919), ('F1', 0.9444444444444445), ('Balanced Accuracy Binary', 0.9605042016806722), ('Accuracy Binary', 0.9576719576719577), ('# Training', 380), ('# Testing', 189)]), 'score': 0.11418110105423404, 'binary_classification_threshold': 0.5}], 'percent_better_than_baseline': 99.21540435103876}}, 'search_order': [0, 1, 2, 3, 4]}