Building a Classification Model with PyCaret


In this example, we're using the PyCaret library to train a classification model. First we initialize the setup for the dataset which in this case is the Titanic dataset. Then we compare different classification models, select the best one before training a final model. Lastly, we make predictions on the test dataset using the trained model.

 1|  from pycaret.classification import *
 3|  # Initialize setup
 4|  setup(train, target='Survived')
 6|  # Compare different models and choose the best one
 7|  best_model = compare_models()
 9|  # Train the chosen model
10|  model = create_model(best_model)
12|  # Make predictions on test data
13|  predictions = predict_model(model, data=test)
Did you find this snippet useful?

Sign up for free to to add this to your code library