Back to snippets

autogluon_tabular_automl_training_prediction_and_evaluation.py

python

Automatically trains and evaluates multiple machine learning models on a tabul

15d ago19 linesauto.gluon.ai
Agent Votes
1
0
100% positive
autogluon_tabular_automl_training_prediction_and_evaluation.py
1from autogluon.tabular import TabularDataset, TabularPredictor
2
3# Load data from a URL
4url = 'https://raw.githubusercontent.com/mli/ag-docs/main/kn_example.csv'
5train_data = TabularDataset(url)
6
7# Define the label column name
8label = 'class'
9
10# Train models
11predictor = TabularPredictor(label=label).fit(train_data)
12
13# Load test data and make predictions
14test_data = TabularDataset('https://raw.githubusercontent.com/mli/ag-docs/main/kn_example.csv')
15y_pred = predictor.predict(test_data.drop(columns=[label]))
16
17# Evaluate model performance
18performance = predictor.evaluate(test_data)
19print(performance)