Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scikit-learn clustering: predict(X) vs. fit_predict(X)

Tags:

In scikit-learn, some clustering algorithms have both predict(X) and fit_predict(X) methods, like KMeans and MeanShift, while others only have the latter, like SpectralClustering. According to the doc:

fit_predict(X[, y]):    Performs clustering on X and returns cluster labels. predict(X): Predict the closest cluster each sample in X belongs to. 

I don't really understand the difference between the two, they seem equivalent to me.

like image 630
student1 Avatar asked May 09 '16 02:05

student1


People also ask

What is difference between fit and fit_predict?

fit() method will fit the model to the input training instances while predict() will perform predictions on the testing instances, based on the learned parameters during fit . On the other hand, fit_predict() is more relevant to unsupervised learning where we don't have labelled inputs.

What is predict () sklearn?

The Sklearn 'Predict' Method Predicts an Output That being the case, it provides a set of tools for doing things like training and evaluating machine learning models. And it also has tools to predict an output value, once the model is trained (for ML techniques that actually make predictions).

What does fit_predict mean?

fit_predict is usually used for unsupervised machine learning transductive estimator. Basically, fit_predict(x) is equivalent to fit(x). predict(x) . Follow this answer to receive notifications.

What is predict () in Python?

Python predict() function enables us to predict the labels of the data values on the basis of the trained model. Syntax: model.predict(data) The predict() function accepts only a single argument which is usually the data to be tested.


Video Answer


2 Answers

In order to use the 'predict' you must use the 'fit' method first. So using 'fit()' and then 'predict()' is definitely the same as using 'fit_predict()'. However, one could benefit from using only 'fit()' in such cases where you need to know the initialization parameters of your models rather than if you use 'fit_predict()', where you will just be obtained the labeling results of running your model on the data.

like image 102
Oer Avatar answered Sep 20 '22 10:09

Oer


fit_predict is usually used for unsupervised machine learning transductive estimator.

Basically, fit_predict(x) is equivalent to fit(x).predict(x).

like image 44
jayesh Avatar answered Sep 17 '22 10:09

jayesh