Not recognizing new distance_threshold parameter for agglomerative clustering

Viewed 2720

The Scikit package doesn't seem to recognize the distance threshold parameter which I am trying to use instead of the n-clusters parameter because I don't know how many clusters I will end up with, it depends on the data.

I am wondering if this is because the distance_threshold parameter was rolled out relatively recently, but I import scikit at the top of the file so I don't see why this would be a problem. Everything works as long as I don't include this parameter.

import matplotlib.pyplot as plt   
%matplotlib inline
from sklearn.cluster import AgglomerativeClustering

cluster = AgglomerativeClustering(affinity='euclidean', linkage='ward', 
distance_threshold = 400.0)  #the last bit here is the problem
cluster.fit_predict(Revs) 
labels = np.array(cluster.labels_).tolist()

It should run the clustering, instead I get this error message:

**TypeError**: __init__() got an unexpected keyword argument 'distance_threshold'
1 Answers

The distance_threshold parameter a new addition in the latest version of sci-kit learn.

New in version 0.21.

Make sure that you library is updated to the latest version. This error is mostly because you are using an older version.

You can check the version as below

import sklearn

# Check version
print(sklearn.__version__)
0.21.

It wil display the version of your sci-kit learn library. To use distance_threshold parameter, the version must be 0.21.

Related