Predicting Columns in a Table - Quick Start¶
Via a simple fit()
call, AutoGluon can produce highly-accurate
models to predict the values in one column of a data table based on the
rest of the columns’ values. Use AutoGluon with tabular data for both
classification and regression problems. This tutorial demonstrates how
to use AutoGluon to produce a classification model that predicts whether
or not a person’s income exceeds $50,000.
To start, import AutoGluon’s TabularPredictor and TabularDataset classes:
from autogluon.tabular import TabularDataset, TabularPredictor
Load training data from a CSV file into an AutoGluon Dataset object. This object is essentially equivalent to a Pandas DataFrame and the same methods can be applied to both.
train_data = TabularDataset('https://autogluon.s3.amazonaws.com/datasets/Inc/train.csv')
subsample_size = 500 # subsample subset of data for faster demo, try setting this to much larger values
train_data = train_data.sample(n=subsample_size, random_state=0)
train_data.head()
age | workclass | fnlwgt | education | education-num | marital-status | occupation | relationship | race | sex | capital-gain | capital-loss | hours-per-week | native-country | class | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
6118 | 51 | Private | 39264 | Some-college | 10 | Married-civ-spouse | Exec-managerial | Wife | White | Female | 0 | 0 | 40 | United-States | >50K |
23204 | 58 | Private | 51662 | 10th | 6 | Married-civ-spouse | Other-service | Wife | White | Female | 0 | 0 | 8 | United-States | <=50K |
29590 | 40 | Private | 326310 | Some-college | 10 | Married-civ-spouse | Craft-repair | Husband | White | Male | 0 | 0 | 44 | United-States | <=50K |
18116 | 37 | Private | 222450 | HS-grad | 9 | Never-married | Sales | Not-in-family | White | Male | 0 | 2339 | 40 | El-Salvador | <=50K |
33964 | 62 | Private | 109190 | Bachelors | 13 | Married-civ-spouse | Exec-managerial | Husband | White | Male | 15024 | 0 | 40 | United-States | >50K |
Note that we loaded data from a CSV file stored in the cloud (AWS s3
bucket), but you can you specify a local
file-path instead if you have already downloaded the CSV file to your
own machine (e.g., using wget).
Each row in the table train_data
corresponds to a single training
example. In this particular dataset, each row corresponds to an
individual person, and the columns contain various characteristics
reported during a census.
Let’s first use these features to predict whether the person’s income
exceeds $50,000 or not, which is recorded in the class
column of
this table.
label = 'class'
print("Summary of class variable: \n", train_data[label].describe())
Summary of class variable:
count 500
unique 2
top <=50K
freq 365
Name: class, dtype: object
Now use AutoGluon to train multiple models:
save_path = 'agModels-predictClass' # specifies folder to store trained models
predictor = TabularPredictor(label=label, path=save_path).fit(train_data)
Beginning AutoGluon training ...
AutoGluon will save models to "agModels-predictClass/"
AutoGluon Version: 0.1.1b20210310
Train Data Rows: 500
Train Data Columns: 14
Preprocessing data ...
AutoGluon infers your prediction problem is: 'binary' (because only two unique label-values observed).
2 unique label values: [' >50K', ' <=50K']
If 'binary' is not the correct problem_type, please manually specify the problem_type argument in fit() (You may specify problem_type as one of: ['binary', 'multiclass', 'regression'])
Selected class <--> label mapping: class 1 = >50K, class 0 = <=50K
Note: For your binary classification, AutoGluon arbitrarily selected which label-value represents positive ( >50K) vs negative ( <=50K) class.
To explicitly set the positive_class, either rename classes to 1 and 0, or specify positive_class in Predictor init.
Using Feature Generators to preprocess the data ...
Fitting AutoMLPipelineFeatureGenerator...
Available Memory: 18070.93 MB
Train Data (Original) Memory Usage: 0.29 MB (0.0% of available memory)
Inferring data type of each feature based on column values. Set feature_metadata_in to manually specify special dtypes of the features.
Stage 1 Generators:
Fitting AsTypeFeatureGenerator...
Stage 2 Generators:
Fitting FillNaFeatureGenerator...
Stage 3 Generators:
Fitting IdentityFeatureGenerator...
Fitting CategoryFeatureGenerator...
Fitting CategoryMemoryMinimizeFeatureGenerator...
Stage 4 Generators:
Fitting DropUniqueFeatureGenerator...
Types of features in original data (raw dtype, special dtypes):
('int', []) : 6 | ['age', 'fnlwgt', 'education-num', 'capital-gain', 'capital-loss', ...]
('object', []) : 8 | ['workclass', 'education', 'marital-status', 'occupation', 'relationship', ...]
Types of features in processed data (raw dtype, special dtypes):
('category', []) : 8 | ['workclass', 'education', 'marital-status', 'occupation', 'relationship', ...]
('int', []) : 6 | ['age', 'fnlwgt', 'education-num', 'capital-gain', 'capital-loss', ...]
0.1s = Fit runtime
14 features in original data used to generate 14 features in processed data.
Train Data (Processed) Memory Usage: 0.03 MB (0.0% of available memory)
Data preprocessing and feature engineering runtime = 0.07s ...
AutoGluon will gauge predictive performance using evaluation metric: 'accuracy'
To change this, specify the eval_metric argument of fit()
Automatically generating train/validation split with holdout_frac=0.2, Train Rows: 400, Val Rows: 100
Fitting model: RandomForestGini ...
0.84 = Validation accuracy score
0.51s = Training runtime
0.11s = Validation runtime
Fitting model: RandomForestEntr ...
0.83 = Validation accuracy score
0.5s = Training runtime
0.11s = Validation runtime
Fitting model: ExtraTreesGini ...
0.83 = Validation accuracy score
0.4s = Training runtime
0.11s = Validation runtime
Fitting model: ExtraTreesEntr ...
0.84 = Validation accuracy score
0.41s = Training runtime
0.11s = Validation runtime
Fitting model: KNeighborsUnif ...
0.73 = Validation accuracy score
0.0s = Training runtime
0.1s = Validation runtime
Fitting model: KNeighborsDist ...
0.65 = Validation accuracy score
0.0s = Training runtime
0.1s = Validation runtime
Fitting model: LightGBM ...
0.85 = Validation accuracy score
0.21s = Training runtime
0.01s = Validation runtime
Fitting model: LightGBMXT ...
0.83 = Validation accuracy score
0.12s = Training runtime
0.01s = Validation runtime
Fitting model: CatBoost ...
0.84 = Validation accuracy score
0.4s = Training runtime
0.01s = Validation runtime
Fitting model: XGBoost ...
0.85 = Validation accuracy score
0.17s = Training runtime
0.02s = Validation runtime
Fitting model: NeuralNetMXNet ...
0.84 = Validation accuracy score
5.61s = Training runtime
0.02s = Validation runtime
Fitting model: NeuralNetFastAI ...
/var/lib/jenkins/workspace/workspace/autogluon-tutorial-tabular-v3/venv/lib/python3.7/site-packages/torch/cuda/__init__.py:52: UserWarning: CUDA initialization: The NVIDIA driver on your system is too old (found version 10010). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver. (Triggered internally at /pytorch/c10/cuda/CUDAFunctions.cpp:109.)
return torch._C._cuda_getDeviceCount() > 0
█
0.83 = Validation accuracy score
6.94s = Training runtime
0.08s = Validation runtime
Fitting model: LightGBMLarge ...
0.83 = Validation accuracy score
0.33s = Training runtime
0.01s = Validation runtime
█
Fitting model: WeightedEnsemble_L2 ...
0.85 = Validation accuracy score
0.37s = Training runtime
0.0s = Validation runtime
AutoGluon training complete, total runtime = 17.93s ...
TabularPredictor saved. To load, use: predictor = TabularPredictor.load("agModels-predictClass/")
Next, load separate test data to demonstrate how to make predictions on new examples at inference time:
test_data = TabularDataset('https://autogluon.s3.amazonaws.com/datasets/Inc/test.csv')
y_test = test_data[label] # values to predict
test_data_nolab = test_data.drop(columns=[label]) # delete label column to prove we're not cheating
test_data_nolab.head()
Loaded data from: https://autogluon.s3.amazonaws.com/datasets/Inc/test.csv | Columns = 15 / 15 | Rows = 9769 -> 9769
age | workclass | fnlwgt | education | education-num | marital-status | occupation | relationship | race | sex | capital-gain | capital-loss | hours-per-week | native-country | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 31 | Private | 169085 | 11th | 7 | Married-civ-spouse | Sales | Wife | White | Female | 0 | 0 | 20 | United-States |
1 | 17 | Self-emp-not-inc | 226203 | 12th | 8 | Never-married | Sales | Own-child | White | Male | 0 | 0 | 45 | United-States |
2 | 47 | Private | 54260 | Assoc-voc | 11 | Married-civ-spouse | Exec-managerial | Husband | White | Male | 0 | 1887 | 60 | United-States |
3 | 21 | Private | 176262 | Some-college | 10 | Never-married | Exec-managerial | Own-child | White | Female | 0 | 0 | 30 | United-States |
4 | 17 | Private | 241185 | 12th | 8 | Never-married | Prof-specialty | Own-child | White | Male | 0 | 0 | 20 | United-States |
We use our trained models to make predictions on the new data and then evaluate performance:
predictor = TabularPredictor.load(save_path) # unnecessary, just demonstrates how to load previously-trained predictor from file
y_pred = predictor.predict(test_data_nolab)
print("Predictions: \n", y_pred)
perf = predictor.evaluate_predictions(y_true=y_test, y_pred=y_pred, auxiliary_metrics=True)
Evaluation: accuracy on test data: 0.8397993653393387
Evaluations on test data:
{
"accuracy": 0.8397993653393387,
"accuracy_score": 0.8397993653393387,
"balanced_accuracy_score": 0.7437076677780596,
"matthews_corrcoef": 0.5295565206264157,
"f1_score": 0.8397993653393387
}
Predictions:
0 <=50K
1 <=50K
2 >50K
3 <=50K
4 <=50K
...
9764 <=50K
9765 <=50K
9766 <=50K
9767 <=50K
9768 <=50K
Name: class, Length: 9769, dtype: object
Detailed (per-class) classification report:
{
" <=50K": {
"precision": 0.8714970966927543,
"recall": 0.9265870352972755,
"f1-score": 0.8981981395953945,
"support": 7451
},
" >50K": {
"precision": 0.7038440714672441,
"recall": 0.5608283002588438,
"f1-score": 0.6242496998799519,
"support": 2318
},
"accuracy": 0.8397993653393387,
"macro avg": {
"precision": 0.7876705840799992,
"recall": 0.7437076677780596,
"f1-score": 0.7612239197376732,
"support": 9769
},
"weighted avg": {
"precision": 0.8317161864181374,
"recall": 0.8397993653393387,
"f1-score": 0.8331953262818111,
"support": 9769
}
}
Now you’re ready to try AutoGluon on your own tabular datasets! As long as they’re stored in a popular format like CSV, you should be able to achieve strong predictive performance with just 2 lines of code:
from autogluon.tabular import TabularPredictor
predictor = TabularPredictor(label=<variable-name>).fit(train_data=<file-name>)
Note: This simple call to fit()
is intended for your first
prototype model. In a subsequent section, we’ll demonstrate how to
maximize predictive performance by additionally specifying two fit()
arguments: presets
and eval_metric
.
Description of fit():¶
Here we discuss what happened during fit()
.
Since there are only two possible values of the class
variable, this
was a binary classification problem, for which an appropriate
performance metric is accuracy. AutoGluon automatically infers this as
well as the type of each feature (i.e., which columns contain continuous
numbers vs. discrete categories). AutogGluon can also automatically
handle common issues like missing data and rescaling feature values.
We did not specify separate validation data and so AutoGluon automatically choses a random training/validation split of the data. The data used for validation is seperated from the training data and is used to determine the models and hyperparameter-values that produce the best results. Rather than just a single model, AutoGluon trains multiple models and ensembles them together to ensure superior predictive performance.
By default, AutoGluon tries to fit various types of models including neural networks and tree ensembles. Each type of model has various hyperparameters, which traditionally, the user would have to specify. AutoGluon automates this process.
AutoGluon automatically and iteratively tests values for hyperparameters
to produce the best performance on the validation data. This involves
repeatedly training models under different hyperparameter settings and
evaluating their performance. This process can be
computationally-intensive, so fit()
can parallelize this process
across multiple threads (and machines if distributed resources are
available). To control runtimes, you can specify various arguments in
fit() as demonstrated in the subsequent In-Depth tutorial.
For tabular problems, fit()
returns a Predictor
object. For
classification, you can easily output predicted class probabilities
instead of predicted classes:
pred_probs = predictor.predict_proba(test_data_nolab)
pred_probs.head(5)
<=50K | >50K | |
---|---|---|
0 | 0.949797 | 0.050203 |
1 | 0.945973 | 0.054027 |
2 | 0.433299 | 0.566701 |
3 | 0.991393 | 0.008607 |
4 | 0.949908 | 0.050092 |
Besides inference, this object can also summarize what happened during fit.
results = predictor.fit_summary()
* Summary of fit() * Estimated performance of each model: model score_val pred_time_val fit_time pred_time_val_marginal fit_time_marginal stack_level can_infer fit_order 0 LightGBM 0.85 0.010873 0.206943 0.010873 0.206943 1 True 7 1 WeightedEnsemble_L2 0.85 0.011492 0.577550 0.000619 0.370607 2 True 14 2 XGBoost 0.85 0.019829 0.167354 0.019829 0.167354 1 True 10 3 CatBoost 0.84 0.008948 0.397863 0.008948 0.397863 1 True 9 4 NeuralNetMXNet 0.84 0.024266 5.614120 0.024266 5.614120 1 True 11 5 ExtraTreesEntr 0.84 0.107019 0.405166 0.107019 0.405166 1 True 4 6 RandomForestGini 0.84 0.107367 0.506588 0.107367 0.506588 1 True 1 7 LightGBMLarge 0.83 0.009845 0.334303 0.009845 0.334303 1 True 13 8 LightGBMXT 0.83 0.012044 0.117859 0.012044 0.117859 1 True 8 9 NeuralNetFastAI 0.83 0.084594 6.938200 0.084594 6.938200 1 True 12 10 RandomForestEntr 0.83 0.107356 0.503499 0.107356 0.503499 1 True 2 11 ExtraTreesGini 0.83 0.108214 0.403289 0.108214 0.403289 1 True 3 12 KNeighborsUnif 0.73 0.103051 0.001877 0.103051 0.001877 1 True 5 13 KNeighborsDist 0.65 0.103031 0.001852 0.103031 0.001852 1 True 6 Number of models trained: 14 Types of models trained: {'XTModel', 'WeightedEnsembleModel', 'XGBoostModel', 'KNNModel', 'LGBModel', 'NNFastAiTabularModel', 'RFModel', 'CatBoostModel', 'TabularNeuralNetModel'} Bagging used: False Multi-layer stack-ensembling used: False Feature Metadata (Processed): (raw dtype, special dtypes): ('category', []) : 8 | ['workclass', 'education', 'marital-status', 'occupation', 'relationship', ...] ('int', []) : 6 | ['age', 'fnlwgt', 'education-num', 'capital-gain', 'capital-loss', ...] Plot summary of models saved to file: agModels-predictClass/SummaryOfModels.html * End of fit() summary *
From this summary, we can see that AutoGluon trained many different types of models as well as an ensemble of the best-performing models. The summary also describes the actual models that were trained during fit and how well each model performed on the held-out validation data. We can view what properties AutoGluon automatically inferred about our prediction task:
print("AutoGluon infers problem type is: ", predictor.problem_type)
print("AutoGluon identified the following types of features:")
print(predictor.feature_metadata)
AutoGluon infers problem type is: binary
AutoGluon identified the following types of features:
('category', []) : 8 | ['workclass', 'education', 'marital-status', 'occupation', 'relationship', ...]
('int', []) : 6 | ['age', 'fnlwgt', 'education-num', 'capital-gain', 'capital-loss', ...]
AutoGluon correctly recognized our prediction problem to be a binary
classification task and decided that variables such as age
should
be represented as integers, whereas variables such as workclass
should be represented as categorical objects. The feature_metadata
attribute allows you to see the inferred data type of each predictive
variable after preprocessing (this is it’s raw dtype; some features
may also be associated with additional special dtypes if produced via
feature-engineering, e.g. numerical representations of a datetime/text
column).
We can evaluate the performance of each individual trained model on our (labeled) test data:
predictor.leaderboard(test_data, silent=True)
█
model | score_test | score_val | pred_time_test | pred_time_val | fit_time | pred_time_test_marginal | pred_time_val_marginal | fit_time_marginal | stack_level | can_infer | fit_order | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | XGBoost | 0.842666 | 0.85 | 0.076577 | 0.019829 | 0.167354 | 0.076577 | 0.019829 | 0.167354 | 1 | True | 10 |
1 | RandomForestGini | 0.841335 | 0.84 | 0.115689 | 0.107367 | 0.506588 | 0.115689 | 0.107367 | 0.506588 | 1 | True | 1 |
2 | RandomForestEntr | 0.840721 | 0.83 | 0.116457 | 0.107356 | 0.503499 | 0.116457 | 0.107356 | 0.503499 | 1 | True | 2 |
3 | LightGBM | 0.839799 | 0.85 | 0.024109 | 0.010873 | 0.206943 | 0.024109 | 0.010873 | 0.206943 | 1 | True | 7 |
4 | WeightedEnsemble_L2 | 0.839799 | 0.85 | 0.025977 | 0.011492 | 0.577550 | 0.001868 | 0.000619 | 0.370607 | 2 | True | 14 |
5 | LightGBMXT | 0.839390 | 0.83 | 0.018046 | 0.012044 | 0.117859 | 0.018046 | 0.012044 | 0.117859 | 1 | True | 8 |
6 | CatBoost | 0.837957 | 0.84 | 0.018642 | 0.008948 | 0.397863 | 0.018642 | 0.008948 | 0.397863 | 1 | True | 9 |
7 | ExtraTreesEntr | 0.828130 | 0.84 | 0.218134 | 0.107019 | 0.405166 | 0.218134 | 0.107019 | 0.405166 | 1 | True | 4 |
8 | NeuralNetFastAI | 0.827925 | 0.83 | 0.518476 | 0.084594 | 6.938200 | 0.518476 | 0.084594 | 6.938200 | 1 | True | 12 |
9 | LightGBMLarge | 0.827823 | 0.83 | 0.025002 | 0.009845 | 0.334303 | 0.025002 | 0.009845 | 0.334303 | 1 | True | 13 |
10 | ExtraTreesGini | 0.825468 | 0.83 | 0.219586 | 0.108214 | 0.403289 | 0.219586 | 0.108214 | 0.403289 | 1 | True | 3 |
11 | NeuralNetMXNet | 0.824854 | 0.84 | 1.027447 | 0.024266 | 5.614120 | 1.027447 | 0.024266 | 5.614120 | 1 | True | 11 |
12 | KNeighborsUnif | 0.725970 | 0.73 | 0.103980 | 0.103051 | 0.001877 | 0.103980 | 0.103051 | 0.001877 | 1 | True | 5 |
13 | KNeighborsDist | 0.695158 | 0.65 | 0.104647 | 0.103031 | 0.001852 | 0.104647 | 0.103031 | 0.001852 | 1 | True | 6 |
When we call predict()
, AutoGluon automatically predicts with the
model that displayed the best performance on validation data (i.e. the
weighted-ensemble). We can instead specify which model to use for
predictions like this:
predictor.predict(test_data, model='LightGBM')
Above the scores of predictive performance were based on a default evaluation metric (accuracy for binary classification). Performance in certain applications may be measured by different metrics than the ones AutoGluon optimizes for by default. If you know the metric that counts in your application, you should specify it as demonstrated in the next section.
Maximizing predictive performance¶
Note: You should not call fit()
with entirely default arguments
if you are benchmarking AutoGluon-Tabular or hoping to maximize its
accuracy! To get the best predictive accuracy with AutoGluon, you should
generally use it like this:
time_limit = 60 # for quick demonstration only, you should set this to longest time you are willing to wait (in seconds)
metric = 'roc_auc' # specify your evaluation metric here
predictor = TabularPredictor(label, eval_metric=metric).fit(train_data, time_limit=time_limit, presets='best_quality')
predictor.leaderboard(test_data, silent=True)
No path specified. Models will be saved in: "AutogluonModels/ag-20210310_042142/"
Presets specified: ['best_quality']
Beginning AutoGluon training ... Time limit = 60s
AutoGluon will save models to "AutogluonModels/ag-20210310_042142/"
AutoGluon Version: 0.1.1b20210310
Train Data Rows: 500
Train Data Columns: 14
Preprocessing data ...
AutoGluon infers your prediction problem is: 'binary' (because only two unique label-values observed).
2 unique label values: [' >50K', ' <=50K']
If 'binary' is not the correct problem_type, please manually specify the problem_type argument in fit() (You may specify problem_type as one of: ['binary', 'multiclass', 'regression'])
Selected class <--> label mapping: class 1 = >50K, class 0 = <=50K
Note: For your binary classification, AutoGluon arbitrarily selected which label-value represents positive ( >50K) vs negative ( <=50K) class.
To explicitly set the positive_class, either rename classes to 1 and 0, or specify positive_class in Predictor init.
Using Feature Generators to preprocess the data ...
Fitting AutoMLPipelineFeatureGenerator...
Available Memory: 17842.81 MB
Train Data (Original) Memory Usage: 0.29 MB (0.0% of available memory)
Inferring data type of each feature based on column values. Set feature_metadata_in to manually specify special dtypes of the features.
Stage 1 Generators:
Fitting AsTypeFeatureGenerator...
Stage 2 Generators:
Fitting FillNaFeatureGenerator...
Stage 3 Generators:
Fitting IdentityFeatureGenerator...
Fitting CategoryFeatureGenerator...
Fitting CategoryMemoryMinimizeFeatureGenerator...
Stage 4 Generators:
Fitting DropUniqueFeatureGenerator...
Types of features in original data (raw dtype, special dtypes):
('int', []) : 6 | ['age', 'fnlwgt', 'education-num', 'capital-gain', 'capital-loss', ...]
('object', []) : 8 | ['workclass', 'education', 'marital-status', 'occupation', 'relationship', ...]
Types of features in processed data (raw dtype, special dtypes):
('category', []) : 8 | ['workclass', 'education', 'marital-status', 'occupation', 'relationship', ...]
('int', []) : 6 | ['age', 'fnlwgt', 'education-num', 'capital-gain', 'capital-loss', ...]
0.1s = Fit runtime
14 features in original data used to generate 14 features in processed data.
Train Data (Processed) Memory Usage: 0.03 MB (0.0% of available memory)
Data preprocessing and feature engineering runtime = 0.07s ...
AutoGluon will gauge predictive performance using evaluation metric: 'roc_auc'
This metric expects predicted probabilities rather than predicted class labels, so you'll need to use predict_proba() instead of predict()
To change this, specify the eval_metric argument of fit()
Fitting model: RandomForestGini_BAG_L1 ... Training model for up to 59.93s of the 59.93s of remaining time.
0.8753 = Validation roc_auc score
2.53s = Training runtime
0.53s = Validation runtime
Fitting model: RandomForestEntr_BAG_L1 ... Training model for up to 56.8s of the 56.8s of remaining time.
0.881 = Validation roc_auc score
2.53s = Training runtime
0.53s = Validation runtime
Fitting model: ExtraTreesGini_BAG_L1 ... Training model for up to 53.68s of the 53.68s of remaining time.
0.8852 = Validation roc_auc score
2.13s = Training runtime
0.53s = Validation runtime
Fitting model: ExtraTreesEntr_BAG_L1 ... Training model for up to 50.93s of the 50.93s of remaining time.
0.8851 = Validation roc_auc score
2.03s = Training runtime
0.53s = Validation runtime
Fitting model: KNeighborsUnif_BAG_L1 ... Training model for up to 48.29s of the 48.29s of remaining time.
0.5303 = Validation roc_auc score
0.02s = Training runtime
0.51s = Validation runtime
Fitting model: KNeighborsDist_BAG_L1 ... Training model for up to 47.75s of the 47.75s of remaining time.
0.5351 = Validation roc_auc score
0.02s = Training runtime
0.51s = Validation runtime
Fitting model: LightGBM_BAG_L1 ... Training model for up to 47.21s of the 47.21s of remaining time.
0.867 = Validation roc_auc score
0.85s = Training runtime
0.05s = Validation runtime
Fitting model: LightGBMXT_BAG_L1 ... Training model for up to 46.3s of the 46.3s of remaining time.
0.8814 = Validation roc_auc score
0.81s = Training runtime
0.05s = Validation runtime
Fitting model: CatBoost_BAG_L1 ... Training model for up to 45.42s of the 45.42s of remaining time.
0.8875 = Validation roc_auc score
2.98s = Training runtime
0.04s = Validation runtime
Fitting model: XGBoost_BAG_L1 ... Training model for up to 42.38s of the 42.38s of remaining time.
0.8666 = Validation roc_auc score
0.66s = Training runtime
0.04s = Validation runtime
Fitting model: NeuralNetMXNet_BAG_L1 ... Training model for up to 41.62s of the 41.61s of remaining time.
0.8593 = Validation roc_auc score
29.63s = Training runtime
0.12s = Validation runtime
Fitting model: NeuralNetFastAI_BAG_L1 ... Training model for up to 11.82s of the 11.81s of remaining time.
█
Ran out of time, stopping training early.
█
Ran out of time, stopping training early.
█
Time limit exceeded... Skipping NeuralNetFastAI_BAG_L1.
Fitting model: LightGBMLarge_BAG_L1 ... Training model for up to 7.08s of the 7.08s of remaining time.
0.8417 = Validation roc_auc score
1.52s = Training runtime
0.05s = Validation runtime
Completed 1/20 k-fold bagging repeats ...
Fitting model: WeightedEnsemble_L2 ... Training model for up to 59.93s of the 5.47s of remaining time.
0.8969 = Validation roc_auc score
1.16s = Training runtime
0.0s = Validation runtime
AutoGluon training complete, total runtime = 55.7s ...
TabularPredictor saved. To load, use: predictor = TabularPredictor.load("AutogluonModels/ag-20210310_042142/")
model | score_test | score_val | pred_time_test | pred_time_val | fit_time | pred_time_test_marginal | pred_time_val_marginal | fit_time_marginal | stack_level | can_infer | fit_order | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | CatBoost_BAG_L1 | 0.902783 | 0.887489 | 0.074226 | 0.043713 | 2.975208 | 0.074226 | 0.043713 | 2.975208 | 1 | True | 9 |
1 | LightGBMXT_BAG_L1 | 0.900161 | 0.881380 | 0.204584 | 0.047774 | 0.811291 | 0.204584 | 0.047774 | 0.811291 | 1 | True | 8 |
2 | WeightedEnsemble_L2 | 0.899244 | 0.896925 | 8.073555 | 1.280766 | 38.743475 | 0.003484 | 0.001117 | 1.161199 | 2 | True | 13 |
3 | LightGBM_BAG_L1 | 0.892347 | 0.866991 | 0.097116 | 0.047815 | 0.847981 | 0.097116 | 0.047815 | 0.847981 | 1 | True | 7 |
4 | XGBoost_BAG_L1 | 0.891681 | 0.866575 | 0.374291 | 0.038153 | 0.660458 | 0.374291 | 0.038153 | 0.660458 | 1 | True | 10 |
5 | RandomForestEntr_BAG_L1 | 0.890378 | 0.880984 | 0.676133 | 0.533563 | 2.528350 | 0.676133 | 0.533563 | 2.528350 | 1 | True | 2 |
6 | RandomForestGini_BAG_L1 | 0.890334 | 0.875322 | 0.674711 | 0.533554 | 2.531367 | 0.674711 | 0.533554 | 2.531367 | 1 | True | 1 |
7 | ExtraTreesGini_BAG_L1 | 0.877482 | 0.885216 | 1.091366 | 0.533339 | 2.131067 | 1.091366 | 0.533339 | 2.131067 | 1 | True | 3 |
8 | ExtraTreesEntr_BAG_L1 | 0.877277 | 0.885094 | 1.091491 | 0.533654 | 2.029851 | 1.091491 | 0.533654 | 2.029851 | 1 | True | 4 |
9 | LightGBMLarge_BAG_L1 | 0.873756 | 0.841684 | 0.144032 | 0.047232 | 1.520830 | 0.144032 | 0.047232 | 1.520830 | 1 | True | 12 |
10 | NeuralNetMXNet_BAG_L1 | 0.865391 | 0.859280 | 5.608405 | 0.121169 | 29.634859 | 5.608405 | 0.121169 | 29.634859 | 1 | True | 11 |
11 | KNeighborsDist_BAG_L1 | 0.526832 | 0.535099 | 0.518865 | 0.511461 | 0.015219 | 0.518865 | 0.511461 | 0.015219 | 1 | True | 6 |
12 | KNeighborsUnif_BAG_L1 | 0.516726 | 0.530320 | 0.517234 | 0.511594 | 0.015427 | 0.517234 | 0.511594 | 0.015427 | 1 | True | 5 |
This command implements the following strategy to maximize accuracy:
Specify the argument
presets='best_quality'
, which allows AutoGluon to automatically construct powerful model ensembles based on stacking/bagging, and will greatly improve the resulting predictions if granted sufficient training time. The default value ofpresets
is'medium_quality_faster_train'
, which produces less accurate models but facilitates faster prototyping. Withpresets
, you can flexibly prioritize predictive accuracy vs. training/inference speed. For example, if you care less about predictive performance and want to quickly deploy a basic model, consider using:presets=['good_quality_faster_inference_only_refit', 'optimize_for_deployment']
.Provide the
eval_metric
if you know what metric will be used to evaluate predictions in your application. Some other non-default metrics you might use include things like:'f1'
(for binary classification),'roc_auc'
(for binary classification),'log_loss'
(for classification),'mean_absolute_error'
(for regression),'median_absolute_error'
(for regression). You can also define your own custom metric function, see examples in the folder:autogluon/core/metrics/
Include all your data in
train_data
and do not providetuning_data
(AutoGluon will split the data more intelligently to fit its needs).Do not specify the
hyperparameter_tune_kwargs
argument (counterintuitively, hyperparameter tuning is not the best way to spend a limited training time budgets, as model ensembling is often superior). We recommend you only usehyperparameter_tune_kwargs
if your goal is to deploy a single model rather than an ensemble.Do not specify
hyperparameters
argument (allow AutoGluon to adaptively select which models/hyperparameters to use).Set
time_limit
to the longest amount of time (in seconds) that you are willing to wait. AutoGluon’s predictive performance improves the longerfit()
is allowed to run.
Regression (predicting numeric table columns):¶
To demonstrate that fit()
can also automatically handle regression
tasks, we now try to predict the numeric age
variable in the same
table based on the other features:
age_column = 'age'
print("Summary of age variable: \n", train_data[age_column].describe())
Summary of age variable:
count 500.00000
mean 39.65200
std 13.52393
min 17.00000
25% 29.00000
50% 38.00000
75% 49.00000
max 85.00000
Name: age, dtype: float64
We again call fit()
, imposing a time-limit this time (in seconds),
and also demonstrate a shorthand method to evaluate the resulting model
on the test data (which contain labels):
predictor_age = TabularPredictor(label=age_column, path="agModels-predictAge").fit(train_data, time_limit=60)
performance = predictor_age.evaluate(test_data)
Beginning AutoGluon training ... Time limit = 60s
AutoGluon will save models to "agModels-predictAge/"
AutoGluon Version: 0.1.1b20210310
Train Data Rows: 500
Train Data Columns: 14
Preprocessing data ...
AutoGluon infers your prediction problem is: 'regression' (because dtype of label-column == int and many unique label-values observed).
Label info (max, min, mean, stddev): (85, 17, 39.652, 13.52393)
If 'regression' is not the correct problem_type, please manually specify the problem_type argument in fit() (You may specify problem_type as one of: ['binary', 'multiclass', 'regression'])
Using Feature Generators to preprocess the data ...
Fitting AutoMLPipelineFeatureGenerator...
Available Memory: 17775.7 MB
Train Data (Original) Memory Usage: 0.32 MB (0.0% of available memory)
Inferring data type of each feature based on column values. Set feature_metadata_in to manually specify special dtypes of the features.
Stage 1 Generators:
Fitting AsTypeFeatureGenerator...
Stage 2 Generators:
Fitting FillNaFeatureGenerator...
Stage 3 Generators:
Fitting IdentityFeatureGenerator...
Fitting CategoryFeatureGenerator...
Fitting CategoryMemoryMinimizeFeatureGenerator...
Stage 4 Generators:
Fitting DropUniqueFeatureGenerator...
Types of features in original data (raw dtype, special dtypes):
('int', []) : 5 | ['fnlwgt', 'education-num', 'capital-gain', 'capital-loss', 'hours-per-week']
('object', []) : 9 | ['workclass', 'education', 'marital-status', 'occupation', 'relationship', ...]
Types of features in processed data (raw dtype, special dtypes):
('category', []) : 9 | ['workclass', 'education', 'marital-status', 'occupation', 'relationship', ...]
('int', []) : 5 | ['fnlwgt', 'education-num', 'capital-gain', 'capital-loss', 'hours-per-week']
0.1s = Fit runtime
14 features in original data used to generate 14 features in processed data.
Train Data (Processed) Memory Usage: 0.03 MB (0.0% of available memory)
Data preprocessing and feature engineering runtime = 0.08s ...
AutoGluon will gauge predictive performance using evaluation metric: 'root_mean_squared_error'
To change this, specify the eval_metric argument of fit()
Automatically generating train/validation split with holdout_frac=0.2, Train Rows: 400, Val Rows: 100
Fitting model: RandomForestMSE ... Training model for up to 59.92s of the 59.92s of remaining time.
-11.6028 = Validation root_mean_squared_error score
0.5s = Training runtime
0.11s = Validation runtime
Fitting model: ExtraTreesMSE ... Training model for up to 59.3s of the 59.3s of remaining time.
-11.7519 = Validation root_mean_squared_error score
0.4s = Training runtime
0.11s = Validation runtime
Fitting model: KNeighborsUnif ... Training model for up to 58.77s of the 58.77s of remaining time.
-15.6869 = Validation root_mean_squared_error score
0.0s = Training runtime
0.1s = Validation runtime
Fitting model: KNeighborsDist ... Training model for up to 58.66s of the 58.66s of remaining time.
-15.1801 = Validation root_mean_squared_error score
0.0s = Training runtime
0.1s = Validation runtime
Fitting model: LightGBM ... Training model for up to 58.55s of the 58.55s of remaining time.
-11.9295 = Validation root_mean_squared_error score
0.19s = Training runtime
0.01s = Validation runtime
Fitting model: LightGBMXT ... Training model for up to 58.35s of the 58.35s of remaining time.
-11.8147 = Validation root_mean_squared_error score
0.19s = Training runtime
0.01s = Validation runtime
Fitting model: CatBoost ... Training model for up to 58.15s of the 58.15s of remaining time.
-11.7448 = Validation root_mean_squared_error score
0.36s = Training runtime
0.01s = Validation runtime
Fitting model: XGBoost ... Training model for up to 57.78s of the 57.78s of remaining time.
-12.1743 = Validation root_mean_squared_error score
0.18s = Training runtime
0.01s = Validation runtime
Fitting model: NeuralNetMXNet ... Training model for up to 57.57s of the 57.57s of remaining time.
-13.1693 = Validation root_mean_squared_error score
3.71s = Training runtime
0.02s = Validation runtime
Fitting model: NeuralNetFastAI ... Training model for up to 53.83s of the 53.83s of remaining time.
█
-39.5057 = Validation root_mean_squared_error score
6.07s = Training runtime
0.11s = Validation runtime
Fitting model: LightGBMLarge ... Training model for up to 47.64s of the 47.64s of remaining time.
-12.1676 = Validation root_mean_squared_error score
0.47s = Training runtime
0.01s = Validation runtime
█
Fitting model: WeightedEnsemble_L2 ... Training model for up to 59.92s of the 46.34s of remaining time.
-11.211 = Validation root_mean_squared_error score
0.42s = Training runtime
0.0s = Validation runtime
AutoGluon training complete, total runtime = 14.09s ...
TabularPredictor saved. To load, use: predictor = TabularPredictor.load("agModels-predictAge/")
Predictive performance on given data: root_mean_squared_error = 10.65874213399807
Note that we didn’t need to tell AutoGluon this is a regression problem,
it automatically inferred this from the data and reported the
appropriate performance metric (RMSE by default). To specify a
particular evaluation metric other than the default, set the
eval_metric
argument of fit()
and AutoGluon will tailor its
models to optimize your metric (e.g.
eval_metric = 'mean_absolute_error'
). For evaluation metrics where
higher values are worse (like RMSE), AutoGluon may sometimes flips their
sign and print them as negative values during training (as it internally
assumes higher values are better).
Data Formats: AutoGluon can currently operate on data tables already loaded into Python as pandas DataFrames, or those stored in files of CSV format or Parquet format. If your data live in multiple tables, you will first need to join them into a single table whose rows correspond to statistically independent observations (datapoints) and columns correspond to different features (aka. variables/covariates).
Refer to the TabularPredictor documentation to see all of the available methods/options.