#!/usr/bin/env python # coding: utf-8 # In[1]: from pycaret.classification import * from pycaret.datasets import get_data import pandas as pd # ## Getting the dataset # In[2]: #get dataset dataset = get_data('bank') # In[3]: #check the shape of data dataset.shape # In[5]: dataset.isna().sum() # In[6]: ## sample returns a random sample from an axis of the object. That would be 38,429 samples, not 45211 data = dataset.sample(frac=0.85, random_state=456) # In[7]: data # In[8]: # remove from the original dataset this random data data_unseen = dataset.drop(data.index) data_unseen # In[9]: # Reseting the index of both datasets data.reset_index(inplace=True, drop=True) data_unseen.reset_index(inplace=True, drop=True) print('Data for Modeling: ' + str(data.shape)) print('Unseen Data For Predictions: ' + str(data_unseen.shape)) # In[10]: model_setup = setup(data=data, target='deposit', session_id=321) # ## Compare Model # In[11]: #Compare Model best_model = compare_models() # In[12]: print(best_model) # ## Create the Model # In[13]: models() # In[14]: gbc = create_model('gbc') # In[15]: #trained model object is stored in the variable 'gbc'. print(gbc) # ## Tunning the Model # In[17]: # Accuracy in previous model is 0.9056 and in the tuned model accuracy is 0.9065 tuned_gbc = tune_model(gbc) # In[18]: print(tuned_gbc) # ## Plotting the Model # In[19]: ## AUC Plot plot_model(tuned_gbc, plot = 'auc') # In[20]: ## Consufion matrix plot_model(tuned_gbc, plot = 'confusion_matrix') # ## Evaluation the model # # In[21]: ## model performance is to use the evaluate_model() evaluate_model(tuned_gbc) # ## Finalizing the Model # In[22]: final_gbc = finalize_model(tuned_gbc) final_gbc # In[23]: #Final gbc parameters for deployment print(final_gbc) # ## Predicting with the model # In[24]: predict_model(final_gbc) # In[25]: unseen_predictions = predict_model(final_gbc, data=data_unseen) unseen_predictions.head() # ## Save Model # In[26]: save_model(final_gbc, './Pycaret/Final_gbc') # ## Load Model # In[27]: saved_final_gbc = load_model('./Pycaret/Final_gbc') # In[28]: new_prediction = predict_model(saved_final_gbc, data=data_unseen) # In[29]: new_prediction.head() # In[ ]: