<jupyter_start><jupyter_text>Importing Libraries<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import dabl

from kmodes.kmodes import KModes

%matplotlib inline<jupyter_output>C:\Users\VAISSHET\Anaconda3\lib\site-packages\sklearn\experimental\enable_hist_gradient_boosting.py:16: UserWarning: Since version 1.0, it is not needed to import enable_hist_gradient_boosting anymore. HistGradientBoostingClassifier and HistGradientBoostingRegressor are now stable and can be normally imported from sklearn.ensemble.
  warnings.warn(<jupyter_text>Data Preprocessing<jupyter_code>dataset = pd.read_csv('../data/V2_Dummy-Data.csv')
dataset.head(10)
dataset.tail(10)
dataset.drop('Unnamed: 0', axis='columns', inplace=True)
dataset.head(10)
dataset.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 10000 entries, 0 to 9999
Data columns (total 12 columns):
 #   Column             Non-Null Count  Dtype  
---  ------             --------------  -----  
 0   Device_type        10000 non-null  object 
 1   Device_ID          10000 non-null  int64  
 2   Device_brand       10000 non-null  object 
 3   Device_model       10000 non-null  object 
 4   Manufacture_Date   10000 non-null  object 
 5   Allocation_Date    10000 non-null  object 
 6   device_in_use      10000 non-null  object 
 7   water_damage       10000 non-null  object 
 8   device_responsive  10000 non-null  object 
 9   battery_health     10000 non-null  object 
 10  Usage(hrs)         10000 non-null  float64
 11  Latency(ms)        10000 non-null  object 
dtypes: float64(1), int64(1), object(10)
memory usage: 937.6+ KB<jupyter_text>Exploratory Data Analysis<jupyter_code>"""
    Elbow method to find optimal K
"""

cost = []

K = range(1,5)

for num_clusters in list(K):

    kmode = KModes(n_clusters=num_clusters, init = "random", n_init = 5, verbose=1)

    kmode.fit_predict(dataset)

    cost.append(kmode.cost_)

    

plt.plot(K, cost, 'bx-')

plt.xlabel('No. of clusters')

plt.ylabel('Cost')

plt.title('Elbow Method For Optimal k')

plt.show()
# standardizing the data
# from sklearn import preprocessing
# from sklearn.cluster import KMeans
dataset.drop(['Device_ID','Device_type',  'Device_model'], axis=1, inplace=True)
dataset.head(10)
# Building the model with 3 clusters
kmode = KModes(n_clusters=3, init = "random", n_init = 20, verbose=1)
clusters = kmode.fit_predict(dataset)
clusters
# adding clusters to our dataset
dataset.insert(0, "Clusters", clusters, True)
dataset
dabl.plot(dataset, target_col="Clusters")<jupyter_output>Target looks like classification
{'fraction_non_alphanumeric': 0.10239817282070804, 'fraction_numerical': 0.04872478111914732, 'mean_word_length': 3.91214953271028, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '42338', 'license': 'MIT', 'n_tokens_mistral': 994, 'n_tokens_neox': 870, 'n_words': 229, 'path': 'notebooks/.ipynb_checkpoints/V1-STEER EDA-checkpoint.ipynb', 'repo_name': 'vaishakhshetty/STEER-ML', 'size': '2627'}