Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

kmeans sklearn

from sklearn.cluster import KMeans
import numpy as np
X = np.array([[1, 2], [1, 4], [1, 0],
              [10, 2], [10, 4], [10, 0]])
kmeans = KMeans(n_clusters=2, random_state=0).fit(X)
kmeans.labels_

kmeans.predict([[0, 0], [12, 3]])

kmeans.cluster_centers_
Comment

kmeans sklearn

kmean_model = KMeans(init='k-means++',n_clusters = 8,max_iter = 200,n_init=10) #here we are using the KMEANS class and configuring it's parameters such as
# initializor , total number of clusters to apply, maximum iterations and no of times to run the algorithm with different centroid seeds
kmean_model.fit(df)

print(kmean_model.cluster_centers_)
predict = kmean_model.predict(df)

plt.scatter(df.iloc[:,2],df.iloc[:,3],c = predict,cmap = 'viridis')
Comment

PREVIOUS NEXT
Code Example
Python :: code hand tracking 
Python :: Make tkinter window look less blury 
Python :: log transform pandas dataframe 
Python :: strftime python 
Python :: pandas display rows config 
Python :: bail bond cowboys 
Python :: import tknter 
Python :: if a number times a number is true python 
Python :: download maninder in python gui 
Python :: pystfp how to listdir 
Python :: how to add multiple dfs to excel sheet 
Python :: concat tensors pytorch 
Python :: ignore error open file python 
Python :: Embed picture in email using smtplib 
Python :: create new column using dictionary padnas 
Python :: numpy count the number of 1s in array 
Python :: typingclub hack python 
Python :: build spacy custom ner model stackoverflow 
Python :: check value vowel user input python 
Python :: datetime.timedelta months 
Python :: in pandas series hot to count the numer of appearences 
Python :: how to save model to a file python 
Python :: python selenium hide log 
Python :: How do I start a DataFrame index from 1? 
Python :: download stopwords nltk 
Python :: repeat 10 times python 
Python :: How to efficiently find the first index in an array of distinct numbers that is equal to the value at that index? 
Python :: programe to check if a is divisible 
Python :: bring tkinter window to front 
Python :: server error 500 heroku django 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =