Reputation: 1016
As above - I'm trying to create a function for clustering specific data types and displaying them.
The function looks a bit like this at the moment,
def cluster(inputData):
variable_s= inputData.groupby(['x','z', 'c'])['w'].sum().unstack()
## 4 Clusters
model = cluster.MiniBatchKMeans(n_clusters=5)
model.fit(variable_s.fillna(0))
variable_s['kmeans_4'] = model.predict(variable_s.fillna(0))
## 8 Clusters
model = cluster.KMeans(n_clusters=8)
model.fit(variable_s.fillna(0))
variable_s['kmeans_8'] = model.predict(variable_s.fillna(0))
## Looking at hourly distribution.
variable_s_Hourly = variable_s.reset_index(1, inplace=True)
variable_s_Hourly['hour'] = variable_s_Hourly.index.hour
return variable_s, variable_s_Hourly
it uses
from sklearn import cluster
to do the clustering, and it's giving me an error like this,
AttributeError: 'function' object has no attribute 'MiniBatchKMeans'
Any clues on solving this issue? I would have thought the function would be fine as long as the library is imported into the file itself - this is in jupyter notebook :)
Cheers!
Upvotes: 1
Views: 80
Reputation: 428
The function name ("cluster") shadows the import. Change the function name to solve it.
Alternatively, you can give the import an alias:
from sklearn import cluster as clstr
Upvotes: 2