Cross Validation

Screen Link:
https://app.dataquest.io/m/154/cross-validation/2/holdout-validation

My Code:

from sklearn.neighbors import KNeighborsRegressor
from sklearn.metrics import mean_squared_error

train_one = split_one
test_one = split_two
train_two = split_two
test_two = split_one

knn=KNeighborsRegressor()
knn.fit(train_one[['accommodates']],train_one['price'])
test_one['predicted_price']=knn.predict(test_one[['accommodates']])

mse_one=mean_squared_error(test_one['price'],test_one['predicted_price'])
iteration_one_rmse=mse_one**0.5



knn.fit(train_two[['accommodates']],train_two['price'])
test_two['predicted_price']=knn.predict(test_two[['accommodates']])
mse_two=mean_squared_error(test_two['price'],test_two['predicted_price'])
iteration_two_rmse=mse_one**0.5

avg_rmse=np.mean([iteration_one_rmse,iteration_two_rmse])

What I expected to happen: I expected that average rmse is right.

What actually happened: both first and second rmse are 131 point something,I check my code with answer given , I think my code is right.

avg_rmse:131.70294747240013
1 Like

Hey @yashkr666

I believe this is why you are getting the same values.

This should give you the correct answer.

iteration_two_rmse = mse_two**0.5

Let me know if it worked.

Thanks
Raj Tulluri

thanks it worked , my mistake I write mse_one in place of mse_two :+1: :+1: :+1:

1 Like