Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How to get values in each cluster

data = pd.read_csv('filename')

km = KMeans(n_clusters=5).fit(data)

cluster_map = pd.DataFrame()
cluster_map['data_index'] = data.index.values
cluster_map['cluster'] = km.labels_

#Once the DataFrame is available is quite easy to filter, For example, to filter all data points in cluster 3
cluster_map[cluster_map.cluster == 3]
Comment

PREVIOUS NEXT
Code Example
Python :: error 302 heroku django 
Python :: dataset analysis in python photo photoelectric effect 
Python :: print hello in python 
Python :: pristine 
Python :: terneray operator in python 
Python :: line to curve dynamo revit 
Python :: sorted key len python 
Python :: how to remove zero after decimal float python 
Python :: matplotlib annotate align center 
Python :: pandas series add prefix 
Python :: how to print a character n times in python 
Python :: candlesticks python 
Python :: using progress bar with rich python 
Python :: python remove list from nested list 
Python :: extract list from string python 
Python :: matplotlib show image black and white 
Python :: Read multiple csv files into separate dataframes Python 
Python :: import one hot encoder 
Python :: class python example 
Python :: python set union 
Python :: sum in python 
Python :: float and int difference 
Python :: numpy and operator 
Python :: get chrome version with python 
Python :: Matching a pattern in python 
Python :: python input - how to read a number 
Python :: for en python 
Python :: docstring 
Python :: append vector to vector python 
Python :: mad libs generator python tutorial 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =