#!/usr/bin/env python # coding: utf-8 # # PyCaret 2 Clustering Example # This notebook is created using PyCaret 2.0. Last updated : 28-07-2020 # In[1]: # check version from pycaret.utils import version version() # # 1. Loading Dataset # In[2]: from pycaret.datasets import get_data data = get_data('public_health') # # 2. Initialize Setup # In[3]: from pycaret.clustering import * clu1 = setup(data, ignore_features = ['Country Name'], session_id=123, log_experiment=True, log_plots = True, experiment_name='health1') # # 3. Create Model # In[4]: models() # In[5]: kmeans = create_model('kmeans', num_clusters = 4) # In[6]: kmodes = create_model('kmodes', num_clusters = 4) # # 4. Assign Labels # In[7]: kmeans_results = assign_model(kmeans) kmeans_results.head() # # 5. Analyze Model # In[8]: plot_model(kmeans) # In[9]: plot_model(kmeans, feature = 'Country Name', label=True) # In[10]: plot_model(kmeans, plot = 'tsne') # In[11]: plot_model(kmeans, plot = 'elbow') # In[12]: plot_model(kmeans, plot = 'silhouette') # In[13]: plot_model(kmeans, plot = 'distance') # In[14]: plot_model(kmeans, plot = 'distribution') # # 6. Predict Model # In[15]: pred_new = predict_model(kmeans, data=data) pred_new.head() # # 7. Save / Load Model # In[16]: save_model(kmeans, model_name='kmeans') # In[17]: loaded_kmeans = load_model('kmeans') print(loaded_kmeans) # In[18]: from sklearn import set_config set_config(display='diagram') loaded_kmeans[0] # In[19]: from sklearn import set_config set_config(display='text') # # 8. Deploy Model # In[20]: deploy_model(kmeans, model_name = 'kmeans-aws', authentication = {'bucket' : 'pycaret-test'}) # # 9. Get Config / Set Config # In[21]: X = get_config('X') X.head() # In[22]: get_config('seed') # In[23]: from pycaret.clustering import set_config set_config('seed', 999) # In[24]: get_config('seed') # # 10. Get System Logs # In[25]: get_system_logs() # # 11. MLFlow UI # In[26]: get_ipython().system('mlflow ui') # # End # Thank you. For more information / tutorials on PyCaret, please visit https://www.pycaret.org