Reputation: 1
X = dataset[['bmi', 's5', 'bp']]
model4 = LinearRegression()
model4.fit(X,Y)
res4 = model4.fit(X,Y)
rmse4 = np.sqrt(mean_squared_error(res4.predict(X),Y))
print("RMSE for Linear Regression: ", rmse4)
model5 = Lasso()
model5.fit(X,Y)
res5 = model5.fit(X,Y)
rmse5 = np.sqrt(mean_squared_error(res5.predict(X),Y))
print("RMSE for Lasso Regression: ", rmse5)
model6 = Ridge()
model6.fit(X,Y)
res6 = model6.fit(X,Y)
rmse6 = np.sqrt(mean_squared_error(res6.predict(X),Y))
print("RMSE for Ridge Regression: ", rmse6)
I want to print the model name that has lowest RMSE. I know using MIN function will bring the minimum value, but I need to get the result about which model has the lowest RMSE, not the lowest value itself. Thank you for your helping!!
Upvotes: -3
Views: 23
Reputation: 102
Store all the names of the model in a list/dict and in the min function use key parameter to extract the key.
You can try something like this:
rmse_list = {}
rmse_dict['Linear Regression'] = rmse4
rmse_dict['Lasso Regression'] = rmse5
rmse_dict['Ridge Regression'] = rmse6
min_rmse_model = min(rmse_dict, key=rmse_dict.get)
print("Model with lowest RMSE:", min_rmse_model)
print("RMSE:", rmse_dict[min_rmse_model])
Upvotes: 0