Advertisement
teceai

Untitled

May 11th, 2021
2,574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3. from sklearn.cluster import KMeans
  4.  
  5. data = pd.read_csv('/datasets/cars.csv')
  6.  
  7. K = range(1, 10)
  8. for k in K:
  9.     model = KMeans(n_clusters=k, random_state=12345)
  10.     model.fit(data)
  11.     distortion = model.inertia_
  12.     plt.figure(figsize=(12, 8))
  13.     plt.plot(K, distortion, 'bx-')
  14.     plt.xlabel('Число кластеров')
  15.     plt.ylabel('Значение целевой функции')
  16.     plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement