Template request | Bug report | Generate Data Product
Tags: #automl #pandas #snippet #classification #dataframe #visualize #pycaret #operations
Author: Minura Punchihewa
Description: This notebook demonstrates how to use PyCaret to quickly and easily build and evaluate machine learning models for classification tasks.
import pandas as pd
try:
from pycaret.classification import setup, compare_models, evaluate_model, predict_model, finalize_model, \
save_model, load_model, create_docker
except:
! pip install --user pycaret
from pycaret.classification import setup, compare_models, evaluate_model, predict_model, finalize_model, \
save_model, load_model, create_docker
csv_path = "https://raw.githubusercontent.com/MinuraPunchihewa/pycaret-automl/main/data/iris.csv"
target_column = "variety"
df = pd.read_csv(csv_path)
df.head()
# must be called before executing any other function
# can configure many types of transformation operations
# by default Missing Value Imputation, One-Hot Encoding and Train-Test Split operations will be performed
# press enter to continue
grid = setup(data=df, target=target_column)
# uses cross-validation
best_model = compare_models()
print(best_model)
# click on the different plot types to exlpore
# some plots may not work depending on the data and the model
evaluate_model(best_model)
# data should be a DataFrame without label
# predict_model(best_model, new_data)
# trains the model on the entire dataset including the hold-out set
# does not change any parameter of the model
final_model = finalize_model(best_model)
save_model(final_model, "classification_model")
model = load_model("classification_model")
# also creates a requirements.txt file for dependencies
create_docker("classification_model")