Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DeprecationWarning in sklearn MiniBatchKMeans

vectors = model.syn0

n_clusters_kmeans = 20 # more for visualization 100 better for clustering

min_kmeans = MiniBatchKMeans(init='k-means++', n_clusters=n_clusters_kmeans, n_init=10)
min_kmeans.fit(vectors)

X_reduced = TruncatedSVD(n_components=50,  random_state=0).fit_transform(vectors)
X_embedded = TSNE(n_components=2, perplexity=40, verbose=2).fit_transform(X_reduced)

fig = plt.figure(figsize=(10, 10))
ax = plt.axes(frameon=False)
plt.setp(ax, xticks=(), yticks=())
plt.subplots_adjust(left=0.0, bottom=0.0, right=1.0, top=0.9,     wspace=0.0, hspace=0.0)
plt.scatter(X_embedded[:, 0], X_embedded[:, 1], c=None, marker="x")
plt.show()

I want to plot vectors. I am using sklearn.cluster MiniBatchKMeans. Above code is giving me following deprecation error:

/usr/local/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:1328: DeprecationWarning: This function is deprecated. Please call randint(0, 99 + 1) instead 0, n_samples - 1, self.batch_size)

Any suggestions are appreciated. Thanks

like image 961
ssh26 Avatar asked Apr 27 '16 14:04

ssh26


People also ask

How do I ignore warnings in Sklearn?

How do I ignore warning in Sklearn? If you wish to squelch deprecation warnings, you can start Python with -Wi::Deprecation . This sets all deprecation warnings to ignored. There is also an Scikit-beam-specific ~scikit-beam.

What is the default value of N_clusters in K means clustering function in Scikit learn?

Read more in the User Guide. Parameters: n_clustersint, default=8. The number of clusters to form as well as the number of centroids to generate.


1 Answers

This is a known issue and a fix has already been merged for this. Please refer to gh:scikit-learn#6863.

Statistically the next release should be released around Oct. 2016. Till then following are the options:

--> Suppress as mentioned in frist's answer on this question

import warnings
....
min_kmeans = MiniBatchKMeans(...)
with warnings.catch_warnings():
    warnings.simplefilter("ignore", category=DeprecationWarning)
    min_kmeans.fit(vectors)
# Rest part of the code

--> Install scikit-learn from master:

pip install git+git://github.com/scikit-learn/scikit-learn.git
like image 122
Shubham Chaudhary Avatar answered Sep 25 '22 11:09

Shubham Chaudhary