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
[1]:
import evalml X, y = evalml.demos.load_breast_cancer() automl = evalml.automl.AutoMLSearch(problem_type='binary') automl.search(X, y)
2020-08-06 20:15:42,490 featuretools - WARNING Featuretools failed to load plugin nlp_primitives from library nlp_primitives. For a full stack trace, set logging to debug. 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: xgboost, linear_model, catboost, random_forest
/home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/envs/v0.12.2/lib/python3.7/site-packages/evalml/pipelines/components/transformers/preprocessing/text_featurizer.py:31: RuntimeWarning: No text columns were given to TextFeaturizer, component will have no effect warnings.warn("No text columns were given to TextFeaturizer, component will have no effect", RuntimeWarning)
(1/5) Mode Baseline Binary Classification P... Elapsed:00:00 Starting cross validation Finished cross validation - mean Log Loss Binary: 12.868 (2/5) CatBoost Classifier w/ Imputer Elapsed:00:00 Starting cross validation Finished cross validation - mean Log Loss Binary: 0.390 (3/5) XGBoost Classifier w/ Imputer Elapsed:00:00 Starting cross validation Finished cross validation - mean Log Loss Binary: 0.101 (4/5) Random Forest Classifier w/ Imputer Elapsed:00:40 Starting cross validation Finished cross validation - mean Log Loss Binary: 0.123 (5/5) Logistic Regression Classifier w/ Imp... Elapsed:00:42 Starting cross validation Finished cross validation - mean Log Loss Binary: 0.091 Search finished after 00:44 Best pipeline: Logistic Regression Classifier w/ Imputer + Standard Scaler Best pipeline Log Loss Binary: 0.091164
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)
********************************** * CatBoost Classifier w/ Imputer * ********************************** Problem Type: Binary Classification Model Family: CatBoost Pipeline Steps ============== 1. Imputer * categorical_impute_strategy : most_frequent * numeric_impute_strategy : mean * fill_value : None 2. CatBoost Classifier * n_estimators : 10 * eta : 0.03 * max_depth : 6 * bootstrap_type : None Training ======== Training for Binary Classification problems. Total training time (including CV): 0.7 seconds Cross Validation ---------------- Log Loss Binary Accuracy Binary Balanced Accuracy Binary F1 Precision AUC MCC Binary # Training # Testing 0 0.398 0.926 0.910 0.896 0.952 0.984 0.843 379.000 190.000 1 0.391 0.963 0.954 0.949 0.985 0.996 0.922 379.000 190.000 2 0.382 0.963 0.965 0.951 0.932 0.989 0.922 380.000 189.000 mean 0.390 0.951 0.943 0.932 0.956 0.989 0.895 - - std 0.008 0.021 0.029 0.031 0.027 0.006 0.046 - - coef of var 0.020 0.022 0.031 0.034 0.028 0.006 0.051 - -
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)
CatBoost Classifier w/ Imputer {'Imputer': {'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'mean', 'fill_value': None}, 'CatBoost Classifier': {'n_estimators': 10, 'eta': 0.03, 'max_depth': 6, 'bootstrap_type': None}}
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)
Logistic Regression Classifier w/ Imputer + Standard Scaler {'Imputer': {'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'mean', 'fill_value': None}, 'Logistic Regression Classifier': {'penalty': 'l2', 'C': 1.0, 'n_jobs': -1}}
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.044495344161987305, 'cv_data': [{'all_objective_scores': OrderedDict([('Log Loss Binary', 12.906595389677152), ('Accuracy Binary', 0.6263157894736842), ('Balanced Accuracy Binary', 0.5), ('F1', 0.0), ('Precision', 0.0), ('AUC', 0.5), ('MCC Binary', 0.0), ('# Training', 379), ('# Testing', 190)]), 'score': 12.906595389677152, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 12.906595389677149), ('Accuracy Binary', 0.6263157894736842), ('Balanced Accuracy Binary', 0.5), ('F1', 0.0), ('Precision', 0.0), ('AUC', 0.5), ('MCC Binary', 0.0), ('# Training', 379), ('# Testing', 190)]), 'score': 12.906595389677149, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 12.792139405522475), ('Accuracy Binary', 0.6296296296296297), ('Balanced Accuracy Binary', 0.5), ('F1', 0.0), ('Precision', 0.0), ('AUC', 0.5), ('MCC Binary', 0.0), ('# Training', 380), ('# Testing', 189)]), 'score': 12.792139405522475, 'binary_classification_threshold': 0.5}]}, 1: {'id': 1, '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', 'fill_value': None}, 'CatBoost Classifier': {'n_estimators': 10, 'eta': 0.03, 'max_depth': 6, 'bootstrap_type': None}}, 'score': 0.3901007526814435, 'high_variance_cv': False, 'training_time': 0.731755256652832, 'cv_data': [{'all_objective_scores': OrderedDict([('Log Loss Binary', 0.3976961654004939), ('Accuracy Binary', 0.9263157894736842), ('Balanced Accuracy Binary', 0.9099301692507988), ('F1', 0.8955223880597014), ('Precision', 0.9523809523809523), ('AUC', 0.9835483489170316), ('MCC Binary', 0.8425009463611858), ('# Training', 379), ('# Testing', 190)]), 'score': 0.3976961654004939, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.39058702666377215), ('Accuracy Binary', 0.9631578947368421), ('Balanced Accuracy Binary', 0.9535447982009706), ('F1', 0.948905109489051), ('Precision', 0.9848484848484849), ('AUC', 0.9958574979287491), ('MCC Binary', 0.9216584956231404), ('# Training', 379), ('# Testing', 190)]), 'score': 0.39058702666377215, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.38201906598006447), ('Accuracy Binary', 0.9629629629629629), ('Balanced Accuracy Binary', 0.9647058823529412), ('F1', 0.9510489510489512), ('Precision', 0.9315068493150684), ('AUC', 0.9885954381752702), ('MCC Binary', 0.9218075091290715), ('# Training', 380), ('# Testing', 189)]), 'score': 0.38201906598006447, 'binary_classification_threshold': 0.5}]}, 2: {'id': 2, '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', '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': 39.46085238456726, 'cv_data': [{'all_objective_scores': OrderedDict([('Log Loss Binary', 0.11449877552314368), ('Accuracy Binary', 0.9578947368421052), ('Balanced Accuracy Binary', 0.9521836903775595), ('F1', 0.9428571428571428), ('Precision', 0.9565217391304348), ('AUC', 0.9915966386554622), ('MCC Binary', 0.9097672817424011), ('# Training', 379), ('# Testing', 190)]), 'score': 0.11449877552314368, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.07421586432028562), ('Accuracy Binary', 0.9736842105263158), ('Balanced Accuracy Binary', 0.9676293052432241), ('F1', 0.9640287769784172), ('Precision', 0.9852941176470589), ('AUC', 0.9959758551307847), ('MCC Binary', 0.943843520216036), ('# Training', 379), ('# Testing', 190)]), 'score': 0.07421586432028562, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.11418110105423404), ('Accuracy Binary', 0.9576719576719577), ('Balanced Accuracy Binary', 0.9605042016806722), ('F1', 0.9444444444444445), ('Precision', 0.918918918918919), ('AUC', 0.9885954381752701), ('MCC Binary', 0.9112159507396058), ('# Training', 380), ('# Testing', 189)]), 'score': 0.11418110105423404, 'binary_classification_threshold': 0.5}]}, 3: {'id': 3, 'pipeline_name': 'Random Forest Classifier w/ Imputer', 'pipeline_class': evalml.pipelines.utils.make_pipeline.<locals>.GeneratedPipeline, 'pipeline_summary': 'Random Forest Classifier w/ Imputer', 'parameters': {'Imputer': {'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'mean', 'fill_value': None}, 'Random Forest Classifier': {'n_estimators': 100, 'max_depth': 6, 'n_jobs': -1}}, 'score': 0.12253681387225619, 'high_variance_cv': False, 'training_time': 1.8858447074890137, 'cv_data': [{'all_objective_scores': OrderedDict([('Log Loss Binary', 0.13984688783161606), ('Accuracy Binary', 0.9421052631578948), ('Balanced Accuracy Binary', 0.9338975026630371), ('F1', 0.920863309352518), ('Precision', 0.9411764705882353), ('AUC', 0.9893478518167831), ('MCC Binary', 0.8757606542930872), ('# Training', 379), ('# Testing', 190)]), 'score': 0.13984688783161606, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.12010721015394288), ('Accuracy Binary', 0.9631578947368421), ('Balanced Accuracy Binary', 0.9563853710498283), ('F1', 0.9496402877697842), ('Precision', 0.9705882352941176), ('AUC', 0.9893478518167831), ('MCC Binary', 0.9211492315750531), ('# Training', 379), ('# Testing', 190)]), 'score': 0.12010721015394288, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.10765634363120971), ('Accuracy Binary', 0.9735449735449735), ('Balanced Accuracy Binary', 0.973109243697479), ('F1', 0.9645390070921985), ('Precision', 0.9577464788732394), ('AUC', 0.9927971188475391), ('MCC Binary', 0.9435040132749904), ('# Training', 380), ('# Testing', 189)]), 'score': 0.10765634363120971, 'binary_classification_threshold': 0.5}]}, 4: {'id': 4, 'pipeline_name': 'Logistic Regression Classifier w/ Imputer + Standard Scaler', 'pipeline_class': evalml.pipelines.utils.make_pipeline.<locals>.GeneratedPipeline, 'pipeline_summary': 'Logistic Regression Classifier w/ Imputer + Standard Scaler', 'parameters': {'Imputer': {'categorical_impute_strategy': 'most_frequent', 'numeric_impute_strategy': 'mean', 'fill_value': None}, 'Logistic Regression Classifier': {'penalty': 'l2', 'C': 1.0, 'n_jobs': -1}}, 'score': 0.09116380517655302, 'high_variance_cv': False, 'training_time': 1.8748509883880615, 'cv_data': [{'all_objective_scores': OrderedDict([('Log Loss Binary', 0.09347817517438466), ('Accuracy Binary', 0.9789473684210527), ('Balanced Accuracy Binary', 0.9775121316132087), ('F1', 0.971830985915493), ('Precision', 0.971830985915493), ('AUC', 0.9936087110900698), ('MCC Binary', 0.9550242632264173), ('# Training', 379), ('# Testing', 190)]), 'score': 0.09347817517438466, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.08320464479579016), ('Accuracy Binary', 0.9736842105263158), ('Balanced Accuracy Binary', 0.9647887323943662), ('F1', 0.9635036496350364), ('Precision', 1.0), ('AUC', 0.9975144987572494), ('MCC Binary', 0.9445075449666159), ('# Training', 379), ('# Testing', 190)]), 'score': 0.08320464479579016, 'binary_classification_threshold': 0.5}, {'all_objective_scores': OrderedDict([('Log Loss Binary', 0.09680859555948422), ('Accuracy Binary', 0.9735449735449735), ('Balanced Accuracy Binary', 0.9760504201680673), ('F1', 0.9650349650349651), ('Precision', 0.9452054794520548), ('AUC', 0.9906362545018007), ('MCC Binary', 0.9443109474170326), ('# Training', 380), ('# Testing', 189)]), 'score': 0.09680859555948422, 'binary_classification_threshold': 0.5}]}}, 'search_order': [0, 1, 2, 3, 4]}