Issue
I am stuck on this problem:
import numpy as np
from sklearn.neighbors import KNeighborsRegressor
def mae(prediction, target):
return np.sum(np.abs(prediction - target))
knn_model = KNeighborsRegressor(n_neighbors=k)
prediction = knn_model.fit(X_train,y_train)
val_mae = mae(prediction, y_val)
Solution
.fit
returns the actual model object, you need to call .predict
to get predictions
knn_model.fit(X_train,y_train)
prediction = knn_model.predict(X_val)
val_mae = mae(prediction, y_val)
Answered By - lejlot
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.