Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

elbow method k means sklearn

from sklearn.cluster import KMeans
from matplotlib import pyplot as plt

X = # <your_data>
distorsions = []
for k in range(2, 20):
    kmeans = KMeans(n_clusters=k)
    kmeans.fit(X)
    distorsions.append(kmeans.inertia_)

fig = plt.figure(figsize=(15, 5))
plt.plot(range(2, 20), distorsions)
plt.grid(True)
plt.title('Elbow curve')
Comment

PREVIOUS NEXT
Code Example
Python :: flask import jsonify 
Python :: print no new line python 
Python :: print underline text python 
Python :: hand tracking module 
Python :: how to re run code in python 
Python :: regex python multiline 
Python :: how to know if a input is a interger in python 
Python :: extract last value of a column from a dataframe in python 
Python :: cv2 waitkey 
Python :: python divide one column by another 
Python :: streamlit button to load a file 
Python :: How to find all primes less than some upperbound efficiently? 
Python :: how to find word in file python 
Python :: ValueError: There may be at most 1 Subject headers in a message 
Python :: open dicom images python 
Python :: row names pandas 
Python :: create a dataframe with series 
Python :: install scratchattach 
Python :: remove duplicate space in string in pytoon 
Python :: key item loop list python 
Python :: pandas rename index values 
Python :: animate time series python 
Python :: python date from yy/mm/dd to yy-mm-dd 
Python :: append one column pandas dataframe 
Python :: count the frequency of words in a file 
Python :: extract n grams from text python 
Python :: python install tabulate 
Python :: convert files from jpg to png and save in a new directory python 
Python :: OneHotEncoder sklearn python 
Python :: matplotlib add legend axis x 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =