Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

elbow plot for k means clustering

distortions = []
num_clusters = range(1, 7)

# Create a list of distortions from the kmeans function
for i in num_clusters:
    cluster_centers, distortion = kmeans(data[['x_scaled', 'y_scaled']],i)
    distortions.append(distortion)

# Create a data frame with two lists - num_clusters, distortions
elbow_plot = pd.DataFrame({'num_clusters': num_clusters, 'distortions': distortions})

# Creat a line plot of num_clusters and distortions
sns.lineplot(x='num_clusters', y='distortions', data = elbow_plot)
plt.xticks(num_clusters)
plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: python search a string in another string get last result 
Python :: how to form .cleaned data in class based views in django 
Python :: install python package 
Python :: NumPy flipud Example 
Python :: pivot index 
Python :: project euler problem 11 python 
Python :: python dictionary add item 
Python :: closures in python 
Python :: python herencia 
Python :: python compiler online 
Python :: how to convert string into list in python 
Python :: python create null matrix 
Python :: how to convert tensorflow 1.15 model to tflite 
Python :: smooth interpolation python 
Python :: How to add all the numbers of a list using python? 
Python :: split strings around given separator/delimiter 
Python :: python reverse dictionary 
Python :: Encrypting a message in Python 
Python :: how to perform in_order traversal of a binary tree 
Python :: pandas python3 only 
Python :: ++ in python 
Python :: global var in python 
Python :: python math exp 
Python :: Math Module cos() Function in python 
Python :: create a colun in pandas using groupby 
Python :: .squeeze function in numpy 
Python :: comentar codigo en python 
Python :: string slicing python 
Python :: rgb to hex python 
Python :: length of an empty array in python 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =