I currently have no experience with Machine Learning so I decided to try an online course. 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)
CodePudding user response:
.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)