#!/usr/bin/env python # coding: utf-8 # # Installation # In[ ]: # run this cell to install pycaret in Google Colab # !pip install pycaret # In[ ]: # If you are using Jupyter notebook, you can pip install pycaret using jupyter notebook or command line # pip install pycaret # In[1]: from pycaret.utils import version version() # In[ ]: # only run this cell if you are using google colab # from pycaret.utils import enable_colab # enable_colab() # # 1. Importing Dataset # In[2]: from pycaret.datasets import get_data data = get_data('country-data') # # 2. Setting up Environment # In[4]: from pycaret.clustering import * clu1 = setup(data, normalize=True, session_id=786, ignore_features = ['country']) # # 3. Train Clustering Model # In[5]: kmeans = create_model('kmeans') # In[6]: print(kmeans) # In[7]: hclust = create_model('hclust') # In[8]: print(hclust) # # 4. Analyze Trained Model # In[9]: plot_model(kmeans, label=True) # In[10]: plot_model(hclust, label=True) # In[11]: plot_model(kmeans, plot = 'tsne', label=True) # In[12]: plot_model(kmeans, plot = 'elbow') # In[13]: plot_model(kmeans, plot = 'silhouette') # In[14]: plot_model(kmeans, plot = 'distribution', feature = 'income') # # 5. Assign Labels / Predict on new data # In[15]: results = assign_model(kmeans) results.head() # In[ ]: predictions = predict_model(kmeans, data=data) predictions.head() # # Learning Resources: # # - PyCaret Clustering Module : https://www.pycaret.org/clustering # - Clustering Tutorial (Level Beginner) : https://pycaret.org/clu101/ # - Clustering in PyCaret (Video Tutorial) : https://www.youtube.com/watch?v=2oxLDir7foQ