Home > other >  sklearn fit() function's mean
sklearn fit() function's mean

Time:01-06

I'm study about machine learning. While study about sklearn, I got some question about fit function's mean. As I know, that function makes model match to data.

What is the different after fit function?
(a = [1, 2, 3] vs KNeighborsClassifier.fit([a]))
(a = [1, 2, 3] vs PolynomialFeatures.fit([a]))

I want to know result of KNeighborsClassifier.
fit([a]) and a = [1, 2, 3].
So I use list(KNeighborsClassifier.fit([a])).
But is not work.

CodePudding user response:

The fit function is used to fit a model to training data. The model is trained using the training data, and the resulting model parameters are stored in the model object.

The result of calling KNeighborsClassifier.fit([a]) is a trained KNeighborsClassifier object, which you can then use to make predictions on new data. This is why you cannot use the list() on it as it is not a list.

To make predictions with a trained KNeighborsClassifier object, you can use the predict method. For example:

from sklearn.neighbors import KNeighborsClassifier

X = [[0], [1], [2], [3]]
y = [0, 0, 1, 1]

clf = KNeighborsClassifier()
clf.fit(X, y)

pred = clf.predict([[2.5]])
print(pred)  
  • Related