Advertisement
maxim_shlyahtin

lb3

May 21st, 2023
1,191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. from sklearn.datasets import load_iris
  2. from sklearn.cluster import MiniBatchKMeans
  3.  
  4.  
  5. def load():
  6.     X, y = load_iris(return_X_y=True)
  7.     return X[:100]
  8.  
  9.  
  10. def train_and_predict(X, n_clusters=1, random_state=42):
  11.     model = MiniBatchKMeans(n_clusters=n_clusters, random_state=random_state)
  12.     model.fit(X)
  13.     preds = model.predict(X)
  14.     return preds
  15.  
  16.  
  17. def optimal_n_clusters(X, с_clusters=1, random_state=42):
  18.     model = MiniBatchKMeans(n_clusters=с_clusters, random_state=random_state)
  19.     model.fit(X)
  20.     return model.inertia_
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement