Title: Why does the mdentropy tutorial give an error in scikit-learn/sklearn/cluster/k_means_.py?
Tags: python;scikit-learn;k-means;information-theory
Question: Upon doing a tutorial on mutual information in mdentropy package, I am getting the following error:
File "/home/midhun/scikit-learn/sklearn/cluster/k_means_.py", line 994, in fit_predict
return self.fit(X, sample_weight=sample_weight).labels_
TypeError: fit() got an unexpected keyword argument 'sample_weight'
I am using Python 3.6.
Comment: Show the full stack trace of error.


Here is another answer: The sample_weight parameter was added to KMeans and a number of other sklearn estimators back in version 0.20.0:
Beyond this, we have added sample_weight support to several estimators
(including KMeans, BayesianRidge and KernelDensity) and improved
stopping criteria in others (including MLPRegressor,
GradientBoostingRegressor and SGDRegressor).
I suspect that your version of sklearn is before 0.20.0. Take a look at the documentation for the previous stable version, 0.19.2 You can see that fit() did not have a sample_weight parameter. You can solve your problem by updating your sklearn to the latest version, or at least 0.20.0.
Comment for this answer: Can you post the code you used to generate the error and a full stacktrace of the error in question? Create a [Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/mcve).
Comment for this answer: Glad I could help! Consider [upvoting and accepting the answer if it helped you.](https://stackoverflow.com/help/someone-answers)
Comment for this answer: Again I Updated to 0.21.dev0 version of sklearn. It is giving me the same error. numpy 1.21.1,  scipy 1.1.0, Cython: 0.28.5 and pandas: 0.23.4 are installed in my system.
Comment for this answer: Though I updated sklearn, the files of the previous version were not deleted from the installed folder. I deleted all those files and freshly installed sklearn 0.20.0 It works now, ss you answered.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:10/15/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><scikit-learn><k-means><information-theory>', 'Title': 'Why does the mdentropy tutorial give an error in scikit-learn/sklearn/cluster/k_means_.py?', 'ViewCount': 431, 'id': 52822244, 'user_AboutMe': '<p>Learner, Explorer and a Wannabe Programmer</p>\n', 'user_AccountId': 11015014.0, 'user_DisplayName': 'midhun_k_madhu', 'user_Reputation': 61.0, 'user_Views': 15.0, 'user_id': 8091158.0}}