I have a feature set Xtrain with dimensions (n_obs,n_features) and responses ytrain with dim (n_obs) . I am attempting to use KNN as a classifier.
from sklearn.neighbors import KNeighborsClassifier
neigh = KNeighborsClassifier()
clf = neigh(n_neighbors = 10)
clf.fit(Xtrain,ytrain)
I get error message:
TypeError
Traceback (most recent call last)
22 clf = neigh(n_neighbors = 10)
23 # Fit best model to data
24 clf.fit(Xtrain, ytrain)
TypeError: 'KNeighborsClassifier' object is not callable
Not sure what the problem is...any help appreciated.
Try:
clf = KNeighborsClassifier(n_neighbors = 10)
clf.fit(Xtrain,ytrain)
Classifier parameters go inside the constructor. You where trying to create a new object with an already instantiated classifier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With