Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import matplotlib.pyplot as plt
- from sklearn.cluster import KMeans
- data = pd.read_csv('/datasets/cars.csv')
- K=range(1,10)
- plt.figure(figsize=(5, 5))
- plt.grid()
- for k in K:
- model=KMeans(n_clusters=k,random_state=12345)
- model.fit(data)
- distortion=model.inertia_
- plt.plot(k, distortion, 'bx-')
- plt.xlabel('Число кластеров')
- plt.ylabel('Значение целевой функции')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement