Skip to content
Advertisement

How to use Scikit kmeans when I have a dataframe

I have converted my dataset to dataframe. I was wondering how to use it in scikit kmeans or if any other kmeans package available.

JavaScript

Advertisement

Answer

sklearn is fully compatible with pandas DataFrames. Therefore, it’s as simple as:

JavaScript

That 0.6 means you use 60% of your data for training, 40% for testing.

More info here:

http://scikit-learn.org/stable/modules/generated/sklearn.cross_validation.train_test_split.html http://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement