Created
March 20, 2022 18:24
-
-
Save kshirsagarsiddharth/42360f33e22b492e998cb869fd9403ee to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ### Function to test various models | |
| def score_dataset(X_train,X_valid,y_train,y_valid, input_model): | |
| model = input_model | |
| model.fit(X_train,y_train) | |
| preds = model.predict(X_valid) | |
| return np.sqrt(mean_squared_error(y_valid, preds)) | |
| input_model = LinearRegression() | |
| score_dataset(encoded_X_train,encoded_X_valid,y_train,y_valid, input_model) | |
| ########################################################################### | |
| 6461.622027825493 | |
| from sklearn.ensemble import RandomForestRegressor | |
| input_model = RandomForestRegressor() | |
| score_dataset(encoded_X_train,encoded_X_valid,y_train,y_valid, input_model) | |
| ########################################################################### | |
| 6659.178696247147 | |
| from sklearn.tree import DecisionTreeRegressor | |
| input_model = DecisionTreeRegressor() | |
| score_dataset(encoded_X_train,encoded_X_valid,y_train,y_valid, input_model) | |
| ########################################################################### | |
| 10140.359133331578 | |
| from sklearn.svm import SVR | |
| input_model = SVR() | |
| score_dataset(encoded_X_train,encoded_X_valid,y_train,y_valid, input_model) | |
| ########################################################################### | |
| 6756.349149847589 | |
| from sklearn.svm import LinearSVR | |
| input_model = LinearSVR() | |
| score_dataset(encoded_X_train,encoded_X_valid,y_train,y_valid, input_model) | |
| ########################################################################### | |
| 7697.258808841277 | |
| from sklearn.ensemble import GradientBoostingRegressor | |
| input_model = GradientBoostingRegressor() | |
| score_dataset(encoded_X_train,encoded_X_valid,y_train,y_valid, input_model) | |
| ########################################################################### | |
| 6627.035769065205 | |
| from sklearn.linear_model import ElasticNet | |
| input_model = ElasticNet() | |
| score_dataset(encoded_X_train,encoded_X_valid,y_train,y_valid, input_model) | |
| ########################################################################### | |
| 6457.986587252211 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment