Advertisement
Alaricy

Untitled

Sep 16th, 2024
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 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. K=range(1,10)
  7. plt.figure(figsize=(5, 5))
  8. plt.grid()
  9. for k in K:
  10.     model=KMeans(n_clusters=k,random_state=12345)
  11.     model.fit(data)
  12.     distortion=model.inertia_
  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