Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

affinity propagation python

from sklearn.cluster import AffinityPropagation
import numpy as np

X = np.array([[1, 2], [1, 4], [1, 0], [4, 2], [4, 4], [4, 0]])
clustering = AffinityPropagation(affinity = 'euclidean', random_state=5).fit(X)

labels = clustering.labels_ # label to each element
centers = clustering.cluster_centers_ # center of each cluster

# if you need a distance different from euclidean
# calculate your custom, pairwise distance among vectors 
# and store them into a matrix M. 
# Note: cluster_centers are no longer available

clustering = AffinityPropagation(affinity='precomputed', random_state=5).fit(M)
Comment

affinity propagation python


S
array([[ 1.        ,  0.08276253,  0.16227766,  0.47213595,  0.64575131],
       [ 0.08276253,  1.        ,  0.56776436,  0.74456265,  0.09901951],
       [ 0.16227766,  0.56776436,  1.        ,  0.47722558,  0.58257569],
       [ 0.47213595,  0.74456265,  0.47722558,  1.        ,  0.87298335],
       [ 0.64575131,  0.09901951,  0.58257569,  0.87298335,  1.        ]])

Comment

PREVIOUS NEXT
Code Example
Python :: random question generator python 
Python :: creating a virtual environment with django on windows 
Python :: To View the entire Row and Column in a Dataframe 
Python :: continual vs continuous 
Python :: python get file path from in os.walk 
Python :: corr pandas 
Python :: pandas name of day 
Python :: get time python 
Python :: randomforestregressor in sklearn 
Python :: python printing to a file 
Python :: df groupby loop 
Python :: Python Tkinter SpinBox Widget 
Python :: How to generate all the permutations of a set of integers, in Python? 
Python :: how to plotting bar on matplotlib 
Python :: curl python 
Python :: how to find unique values in a column in pandas 
Python :: python check if class has function 
Python :: after groupby how to add values in two rows to a list 
Python :: python extend list 
Python :: python progress bar 
Python :: spacy config 
Python :: django check if user is admin 
Python :: add css in html django 
Python :: python regex tester 
Python :: python replace string 
Python :: how to encode hexadecimal python 
Python :: use a dictionary to make a column of values 
Python :: how to insert a variable into a string python 
Python :: form errors in django 
Python :: python binary remove 0b 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =