In this demo, we will build an optimized lead scoring model using EvalML. To optimize the pipeline, we will set up an objective function to maximize the revenue generated with true positives while taking into account the cost of false positives. At the end of this demo, we also show you how introducing the right objective during the training is over 6x better than using a generic machine learning metric like AUC.
[1]:
import evalml from evalml import AutoMLSearch from evalml.objectives import LeadScoring
To optimize the pipelines toward the specific business needs of this model, you can set your own assumptions for how much value is gained through true positives and the cost associated with false positives. These parameters are
true_positive - dollar amount to be gained with a successful lead
true_positive
false_positive - dollar amount to be lost with an unsuccessful lead
false_positive
Using these parameters, EvalML builds a pileline that will maximize the amount of revenue per lead generated.
[2]:
lead_scoring_objective = LeadScoring( true_positives=1000, false_positives=-10 )
We will be utilizing a dataset detailing a customer’s job, country, state, zip, online action, the dollar amount of that action and whether they were a successful lead.
[3]:
from urllib.request import urlopen import pandas as pd customers_data = urlopen('https://featurelabs-static.s3.amazonaws.com/lead_scoring_ml_apps/customers.csv') interactions_data = urlopen('https://featurelabs-static.s3.amazonaws.com/lead_scoring_ml_apps/interactions.csv') leads_data = urlopen('https://featurelabs-static.s3.amazonaws.com/lead_scoring_ml_apps/previous_leads.csv') customers = pd.read_csv(customers_data) interactions = pd.read_csv(interactions_data) leads = pd.read_csv(leads_data) X = customers.merge(interactions, on='customer_id').merge(leads, on='customer_id') y = X['label'] X = X.drop(['customer_id', 'date_registered', 'birthday','phone', 'email', 'owner', 'company', 'id', 'time_x', 'session', 'referrer', 'time_y', 'label', 'country'], axis=1) display(X.head())
In order to validate the results of the pipeline creation and optimization process, we will save some of our data as a holdout set
EvalML natively supports one-hot encoding and imputation so the above NaN and categorical values will be taken care of.
NaN
[4]:
X_train, X_holdout, y_train, y_holdout = evalml.preprocessing.split_data(X, y, test_size=0.2, random_state=0) print(X.dtypes)
job object state object zip float64 action object amount float64 dtype: object
Because the lead scoring labels are binary, we will use AutoMLSearch(problem_type='binary'). When we call .search(), the search for the best pipeline will begin.
AutoMLSearch(problem_type='binary')
.search()
[5]:
automl = AutoMLSearch(problem_type='binary', objective=lead_scoring_objective, additional_objectives=['auc'], max_batches=1, optimize_thresholds=True) automl.search(X_train, y_train)
`X` passed was not a DataTable. EvalML will try to convert the input as a Woodwork DataTable and types will be inferred. To control this behavior, please pass in a Woodwork DataTable instead. `y` passed was not a DataColumn. EvalML will try to convert the input as a Woodwork DataTable and types will be inferred. To control this behavior, please pass in a Woodwork DataTable instead. {'message': 'The following labels fall below 10% of the target: [True]', 'data_check_name': 'ClassImbalanceDataCheck', 'level': 'warning', 'code': 'CLASS_IMBALANCE_BELOW_THRESHOLD', 'details': {'target_values': [True]}} Generating pipelines to search over... ***************************** * Beginning pipeline search * ***************************** Optimizing for Lead Scoring. Greater score is better. Searching up to 1 batches for a total of 9 pipelines. Allowed model families: decision_tree, linear_model, catboost, lightgbm, xgboost, extra_trees, random_forest
Batch 1: (1/9) Mode Baseline Binary Classification P... Elapsed:00:00 Starting cross validation Finished cross validation - mean Lead Scoring: 0.000 Batch 1: (2/9) Decision Tree Classifier w/ Imputer +... Elapsed:00:01 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean Lead Scoring: nan Batch 1: (3/9) LightGBM Classifier w/ Imputer + Text... Elapsed:00:06 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean Lead Scoring: nan Batch 1: (4/9) Extra Trees Classifier w/ Imputer + T... Elapsed:00:10 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean Lead Scoring: nan Batch 1: (5/9) Elastic Net Classifier w/ Imputer + T... Elapsed:00:14 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean Lead Scoring: nan Batch 1: (6/9) CatBoost Classifier w/ Imputer + Text... Elapsed:00:18 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean Lead Scoring: nan Batch 1: (7/9) XGBoost Classifier w/ Imputer + Text ... Elapsed:00:23 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean Lead Scoring: nan Batch 1: (8/9) Random Forest Classifier w/ Imputer +... Elapsed:00:26 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean Lead Scoring: nan Batch 1: (9/9) Logistic Regression Classifier w/ Imp... Elapsed:00:30 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean Lead Scoring: nan Search finished after 00:34 Best pipeline: Mode Baseline Binary Classification Pipeline Best pipeline Lead Scoring: 0.000000
Once the fitting process is done, we can see all of the pipelines that were searched, ranked by their score on the lead scoring objective we defined
[6]:
automl.rankings
to select the best pipeline we can run
[7]:
best_pipeline = automl.best_pipeline
You can get more details about any pipeline. Including how it performed on other objective functions.
[8]:
automl.describe_pipeline(automl.rankings.iloc[0]["id"])
************************************************ * Mode Baseline Binary Classification Pipeline * ************************************************ Problem Type: binary Model Family: Baseline Pipeline Steps ============== 1. Baseline Classifier * strategy : mode Training ======== Training for binary problems. Objective to optimize binary classification pipeline thresholds for: <evalml.objectives.lead_scoring.LeadScoring object at 0x7f30ac064750> Total training time (including CV): 1.3 seconds Cross Validation ---------------- Lead Scoring AUC # Training # Testing 0 0.000 0.500 2479.000 1550.000 1 0.000 0.500 2479.000 1550.000 2 0.000 0.500 2480.000 1549.000 mean 0.000 0.500 - - std 0.000 0.000 - - coef of var inf 0.000 - -
Finally, we retrain the best pipeline on all of the training data and evaluate on the holdout
[9]:
best_pipeline.fit(X_train, y_train)
ModeBaselineBinaryPipeline(parameters={'Baseline Classifier':{'strategy': 'mode'},})
Now, we can score the pipeline on the hold out data using both the lead scoring score and the AUC.
[10]:
best_pipeline.score(X_holdout, y_holdout, objectives=["auc", lead_scoring_objective])
OrderedDict([('AUC', 0.5), ('Lead Scoring', 0.0)])
To demonstrate the importance of optimizing for the right objective, let’s search for another pipeline using AUC, a common machine learning metric. After that, we will score the holdout data using the lead scoring objective to see how the best pipelines compare.
[11]:
automl_auc = evalml.AutoMLSearch(problem_type='binary', objective='auc', additional_objectives=[], max_batches=1, optimize_thresholds=True) automl_auc.search(X_train, y_train)
`X` passed was not a DataTable. EvalML will try to convert the input as a Woodwork DataTable and types will be inferred. To control this behavior, please pass in a Woodwork DataTable instead. `y` passed was not a DataColumn. EvalML will try to convert the input as a Woodwork DataTable and types will be inferred. To control this behavior, please pass in a Woodwork DataTable instead. {'message': 'The following labels fall below 10% of the target: [True]', 'data_check_name': 'ClassImbalanceDataCheck', 'level': 'warning', 'code': 'CLASS_IMBALANCE_BELOW_THRESHOLD', 'details': {'target_values': [True]}} Generating pipelines to search over... ***************************** * Beginning pipeline search * ***************************** Optimizing for AUC. Greater score is better. Searching up to 1 batches for a total of 9 pipelines. Allowed model families: decision_tree, linear_model, catboost, lightgbm, xgboost, extra_trees, random_forest
Batch 1: (1/9) Mode Baseline Binary Classification P... Elapsed:00:00 Starting cross validation Finished cross validation - mean AUC: 0.500 Batch 1: (2/9) Decision Tree Classifier w/ Imputer +... Elapsed:00:00 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean AUC: nan Batch 1: (3/9) LightGBM Classifier w/ Imputer + Text... Elapsed:00:04 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean AUC: nan Batch 1: (4/9) Extra Trees Classifier w/ Imputer + T... Elapsed:00:09 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean AUC: nan Batch 1: (5/9) Elastic Net Classifier w/ Imputer + T... Elapsed:00:14 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean AUC: nan Batch 1: (6/9) CatBoost Classifier w/ Imputer + Text... Elapsed:00:19 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean AUC: nan Batch 1: (7/9) XGBoost Classifier w/ Imputer + Text ... Elapsed:00:24 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean AUC: nan Batch 1: (8/9) Random Forest Classifier w/ Imputer +... Elapsed:00:28 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean AUC: nan Batch 1: (9/9) Logistic Regression Classifier w/ Imp... Elapsed:00:33 Starting cross validation Fold 0: Encountered an error. Fold 0: All scores will be replaced with nan. Fold 0: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 0: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 1: Encountered an error. Fold 1: All scores will be replaced with nan. Fold 1: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 1: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Fold 2: Encountered an error. Fold 2: All scores will be replaced with nan. Fold 2: Please check /home/docs/checkouts/readthedocs.org/user_builds/feature-labs-inc-evalml/checkouts/v0.16.0/docs/source/demos/evalml_debug.log for the current hyperparameters and stack trace. Fold 2: Exception during automl search: np.nan is an invalid document, expected byte or unicode string. Finished cross validation - mean AUC: nan Search finished after 00:38 Best pipeline: Mode Baseline Binary Classification Pipeline Best pipeline AUC: 0.500000
like before, we can look at the rankings and pick the best pipeline
[12]:
automl_auc.rankings
[13]:
best_pipeline_auc = automl_auc.best_pipeline # train on the full training data best_pipeline_auc.fit(X_train, y_train)
[14]:
# get the auc and lead scoring score on holdout data best_pipeline_auc.score(X_holdout, y_holdout, objectives=["auc", lead_scoring_objective])
When we optimize for AUC, we can see that the AUC score from this pipeline is better than the AUC score from the pipeline optimized for lead scoring. However, the revenue per lead gained was only $7 per lead when optimized for AUC and was $45 when optimized for lead scoring. As a result, we would gain up to 6x the amount of revenue if we optimized for lead scoring.
$7
$45
This happens because optimizing for AUC does not take into account the user-specified true_positive (dollar amount to be gained with a successful lead) and false_positive (dollar amount to be lost with an unsuccessful lead) values. Thus, the best pipelines may produce the highest AUC but may not actually generate the most revenue through lead scoring.
This example highlights how performance in the real world can diverge greatly from machine learning metrics.