Created
March 27, 2020 21:45
-
-
Save aniruddha27/66119a2050fc808d2bdb7d4544ae75b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# training a KNN model | |
from sklearn.neighbors import KNeighborsRegressor | |
# measuring RMSE score | |
from sklearn.metrics import mean_squared_error | |
# knn | |
knn = KNeighborsRegressor(n_neighbors=7) | |
rmse = [] | |
# raw, normalized and standardized training and testing data | |
trainX = [X_train, X_train_norm, X_train_stand] | |
testX = [X_test, X_test_norm, X_test_stand] | |
# model fitting and measuring RMSE | |
for i in range(len(trainX)): | |
# fit | |
knn.fit(trainX[i],y_train) | |
# predict | |
pred = knn.predict(testX[i]) | |
# RMSE | |
rmse.append(np.sqrt(mean_squared_error(y_test,pred))) | |
# visualizing the result | |
df_knn = pd.DataFrame({'RMSE':rmse},index=['Original','Normalized','Standardized']) | |
df_knn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment