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
| from sklearn.model_selection import train_test_split | |
| X = df | |
| y = target | |
| # training and validation set | |
| X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=27) |
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
| from sklearn.linear_model import LinearRegression | |
| from sklearn.metrics import mean_squared_error | |
| lr = LinearRegression() | |
| lr.fit(X_train,y_train) | |
| rmse = np.sqrt(mean_squared_error(y_test,lr.predict(X_test))) | |
| print(rmse) |
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
| from sklearn.linear_model import Ridge | |
| from sklearn.metrics import mean_squared_error | |
| # different alpha values | |
| alphas = [0.01, 0.1, 0.3, 1, 3, 5, 10, 15, 20] | |
| for a in alphas: | |
| lr = Ridge(alpha=a) | |
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
| model = Ridge(alpha=3) | |
| model.fit(X_train,y_train) |
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
| log_pred = model.predict(test) | |
| actual_pred = np.exp(log_pred) |
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
| data_dict = {'Id':test_id,'SalePrice':actual_pred} | |
| submit = pd.DataFrame(data_dict) | |
| submit.to_csv('submission.csv',index=False) |
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
| import pandas as pd | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| plt.style.use('ggplot') |
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
| df = pd.read_csv('drive/My Drive/AV/train.csv') | |
| df.head() |
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
| df.drop(['PassengerId','Ticket','Name'],inplace=True,axis=1) |
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
| #a single index | |
| table = pd.pivot_table(data=df,index=['Sex']) | |
| table |