Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

iterate over k values and plot the inertia values for each k

ks = range(1, 6)
inertias = []

for k in ks:
    # Create a KMeans instance with k clusters: model
    model = KMeans(n_clusters=k)
    
    # Fit model to samples
    model.fit(samples)
    
    # Append the inertia to the list of inertias
    inertias.append(model.inertia_)
    
# Plot ks vs inertias
plt.plot(ks, inertias, '-o')
plt.xlabel('number of clusters, k')
plt.ylabel('inertia')
plt.xticks(ks)
plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: visualising data with tsne 
Python :: sample clustering of articles using kmeans and trncatedSVD 
Python :: django chain query 
Python :: if you have a list and the user input one of the keys then output its value 
Python :: python loop take out element backwardly 
Python :: debug forbidden by robots.txt scrappy 
Python :: Python Code for Checking if a number is an Odd number 
Python :: how to break out of while loop when the user hit ctrl + d python 
Python :: python package for facial emotion recognition 
Python :: connection to python debugger failed: socket closed 
Python :: dropdown menu with selenium python 
Python :: add column to wandb.Table 
Python :: django wsgi application could not be loaded error importing module 
Python :: map column dataframe python 
Python :: python matrices access column 
Python :: python google translator 
Python :: how to usepygame.sprite.spritecollide 
Python :: expecting property name enclosed in double quotes json 
Python :: pd.read_csv how to cumsum a column 
Python :: van first name van second name van last name 
Python :: python input byte array 
Python :: como resolver números primos em python 
Python :: print fps in while loop python 
Python :: python print to string 
Python :: sidetable github 
Python :: sowpods python 
Python :: Gets an existing SparkSession or, if there is no existing one, creates a new one based on the options set in this builder 
Python :: pandas drop a list of rows 
Python :: mask and then fillnan# 
Python :: if i[11] not in lst[i]: 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =