diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index ebbd53a..3613e36 100644 Binary files a/__pycache__/__init__.cpython-36.pyc and b/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_load_data/__pycache__/__init__.cpython-36.pyc b/q01_load_data/__pycache__/__init__.cpython-36.pyc index 745b533..9fc832e 100644 Binary files a/q01_load_data/__pycache__/__init__.cpython-36.pyc and b/q01_load_data/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_load_data/__pycache__/build.cpython-36.pyc b/q01_load_data/__pycache__/build.cpython-36.pyc index 108e4a3..53562e4 100644 Binary files a/q01_load_data/__pycache__/build.cpython-36.pyc and b/q01_load_data/__pycache__/build.cpython-36.pyc differ diff --git a/q01_load_data/build.py b/q01_load_data/build.py index e4cd8e3..98c4f1c 100644 --- a/q01_load_data/build.py +++ b/q01_load_data/build.py @@ -1,10 +1,17 @@ +# %load q01_load_data/build.py # Default imports import pandas as pd from sklearn.model_selection import train_test_split -path = 'data/house_prices_multivariate.csv' +# Write your solution here +def load_data(path, test_s=0.33, Random_state = 9): + df = pd.read_csv(path) + X = df.iloc[:,:-1] + y = df.iloc[:,-1] + X_train, X_test, y_train, y_test = train_test_split(X,y,test_size = test_s, random_state= Random_state) + return df, X_train, X_test, y_train, y_test + -# Write your solution here diff --git a/q01_load_data/tests/__pycache__/__init__.cpython-36.pyc b/q01_load_data/tests/__pycache__/__init__.cpython-36.pyc index 133357e..5d9408a 100644 Binary files a/q01_load_data/tests/__pycache__/__init__.cpython-36.pyc and b/q01_load_data/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_load_data/tests/__pycache__/test_q01_load_data.cpython-36.pyc b/q01_load_data/tests/__pycache__/test_q01_load_data.cpython-36.pyc index 689755b..99b7860 100644 Binary files a/q01_load_data/tests/__pycache__/test_q01_load_data.cpython-36.pyc and b/q01_load_data/tests/__pycache__/test_q01_load_data.cpython-36.pyc differ diff --git a/q02_Max_important_feature/__pycache__/__init__.cpython-36.pyc b/q02_Max_important_feature/__pycache__/__init__.cpython-36.pyc index 93c9119..91b31cc 100644 Binary files a/q02_Max_important_feature/__pycache__/__init__.cpython-36.pyc and b/q02_Max_important_feature/__pycache__/__init__.cpython-36.pyc differ diff --git a/q02_Max_important_feature/__pycache__/build.cpython-36.pyc b/q02_Max_important_feature/__pycache__/build.cpython-36.pyc index 2b7cfd4..6478cc1 100644 Binary files a/q02_Max_important_feature/__pycache__/build.cpython-36.pyc and b/q02_Max_important_feature/__pycache__/build.cpython-36.pyc differ diff --git a/q02_Max_important_feature/build.py b/q02_Max_important_feature/build.py index 51fbde6..ef2e9e7 100644 --- a/q02_Max_important_feature/build.py +++ b/q02_Max_important_feature/build.py @@ -1,3 +1,4 @@ +# %load q02_Max_important_feature/build.py # Default imports from greyatomlib.advanced_linear_regression.q01_load_data.build import load_data @@ -6,3 +7,14 @@ # Write your code here +def Max_important_feature(data_set, target_variable='SalePrice', n=4): + + value = data_set.corr()['SalePrice'].drop('SalePrice').sort_values(ascending=False)[0:4] + + return value.index + + +Max_important_feature(data_set, target_variable='SalePrice', n=4) + + + diff --git a/q02_Max_important_feature/tests/__pycache__/__init__.cpython-36.pyc b/q02_Max_important_feature/tests/__pycache__/__init__.cpython-36.pyc index cec58d4..6901719 100644 Binary files a/q02_Max_important_feature/tests/__pycache__/__init__.cpython-36.pyc and b/q02_Max_important_feature/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q02_Max_important_feature/tests/__pycache__/test_q02max_important_feature.cpython-36.pyc b/q02_Max_important_feature/tests/__pycache__/test_q02max_important_feature.cpython-36.pyc index cb6849b..5e517b0 100644 Binary files a/q02_Max_important_feature/tests/__pycache__/test_q02max_important_feature.cpython-36.pyc and b/q02_Max_important_feature/tests/__pycache__/test_q02max_important_feature.cpython-36.pyc differ diff --git a/q03_polynomial/__pycache__/__init__.cpython-36.pyc b/q03_polynomial/__pycache__/__init__.cpython-36.pyc index aa42922..0128c98 100644 Binary files a/q03_polynomial/__pycache__/__init__.cpython-36.pyc and b/q03_polynomial/__pycache__/__init__.cpython-36.pyc differ diff --git a/q03_polynomial/__pycache__/build.cpython-36.pyc b/q03_polynomial/__pycache__/build.cpython-36.pyc index 3be41d0..7660314 100644 Binary files a/q03_polynomial/__pycache__/build.cpython-36.pyc and b/q03_polynomial/__pycache__/build.cpython-36.pyc differ diff --git a/q03_polynomial/build.py b/q03_polynomial/build.py index 26d8971..b81bad5 100644 --- a/q03_polynomial/build.py +++ b/q03_polynomial/build.py @@ -1,11 +1,32 @@ +# %load q03_polynomial/build.py # Default imports from greyatomlib.advanced_linear_regression.q01_load_data.build import load_data from sklearn.preprocessing import PolynomialFeatures from sklearn.pipeline import make_pipeline from sklearn.linear_model import LinearRegression +from sklearn.pipeline import Pipeline +import numpy as np +from sklearn.model_selection import train_test_split # We have already loaded the data for you data_set, X_train, X_test, y_train, y_test = load_data('data/house_prices_multivariate.csv') # Write your solution here +def polynomial(power=5,Random_state=9): + linear_pipe = make_pipeline(PolynomialFeatures(degree=power,include_bias=False), LinearRegression()) + + cols = data_set.corr()['SalePrice'].drop('SalePrice').sort_values(ascending = False)[0:4].index + X = data_set[cols] +# print(X.shape) + y = data_set['SalePrice'] + X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=9, test_size = 0.33) + + linear_pipe.fit(X_train,y_train) + print(linear_pipe.predict(np.array([4, 5, 6, 7]).reshape(1,-1))) + return linear_pipe +polynomial(power=5,Random_state=9) + + + + diff --git a/q03_polynomial/tests/__pycache__/__init__.cpython-36.pyc b/q03_polynomial/tests/__pycache__/__init__.cpython-36.pyc index 6e20876..7c2be68 100644 Binary files a/q03_polynomial/tests/__pycache__/__init__.cpython-36.pyc and b/q03_polynomial/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q03_polynomial/tests/__pycache__/test_q03_polynomial.cpython-36.pyc b/q03_polynomial/tests/__pycache__/test_q03_polynomial.cpython-36.pyc index ef8c88b..8bb7be9 100644 Binary files a/q03_polynomial/tests/__pycache__/test_q03_polynomial.cpython-36.pyc and b/q03_polynomial/tests/__pycache__/test_q03_polynomial.cpython-36.pyc differ diff --git a/q04_ridge/__pycache__/__init__.cpython-36.pyc b/q04_ridge/__pycache__/__init__.cpython-36.pyc index 4342136..bdda2fc 100644 Binary files a/q04_ridge/__pycache__/__init__.cpython-36.pyc and b/q04_ridge/__pycache__/__init__.cpython-36.pyc differ diff --git a/q04_ridge/__pycache__/build.cpython-36.pyc b/q04_ridge/__pycache__/build.cpython-36.pyc index ea08c01..ef58902 100644 Binary files a/q04_ridge/__pycache__/build.cpython-36.pyc and b/q04_ridge/__pycache__/build.cpython-36.pyc differ diff --git a/q04_ridge/build.py b/q04_ridge/build.py index 9ee00b1..46022c9 100644 --- a/q04_ridge/build.py +++ b/q04_ridge/build.py @@ -1,15 +1,33 @@ +# %load q04_ridge/build.py # Default imports from sklearn.linear_model import Ridge import pandas as pd import numpy as np from sklearn.metrics import mean_squared_error from greyatomlib.advanced_linear_regression.q01_load_data.build import load_data -np.random.seed(9) # We have already loaded the data for you data_set, X_train, X_test, y_train, y_test = load_data('data/house_prices_multivariate.csv') +# np.random.seed(9) + + +#Write your solution here +def ridge(alpha = 0.01): + ridge_mod = Ridge(alpha,normalize=True, random_state=9) + ridge_mod.fit(X_train, y_train) + y_pred = ridge_mod.predict(X_test) + y_tran = ridge_mod.predict(X_train) + RMSE_train = mean_squared_error(y_tran,y_train)**0.5 + RMSE_test = mean_squared_error(y_test,y_pred)**0.5 + + return RMSE_train,RMSE_test,ridge_mod + + + +ridge(alpha = 0.01) + + -# Write your solution here diff --git a/q04_ridge/tests/__pycache__/__init__.cpython-36.pyc b/q04_ridge/tests/__pycache__/__init__.cpython-36.pyc index 6d021b5..61df67a 100644 Binary files a/q04_ridge/tests/__pycache__/__init__.cpython-36.pyc and b/q04_ridge/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q04_ridge/tests/__pycache__/test_q04_ridge.cpython-36.pyc b/q04_ridge/tests/__pycache__/test_q04_ridge.cpython-36.pyc index 0549421..22e282f 100644 Binary files a/q04_ridge/tests/__pycache__/test_q04_ridge.cpython-36.pyc and b/q04_ridge/tests/__pycache__/test_q04_ridge.cpython-36.pyc differ diff --git a/q05_lasso/__pycache__/__init__.cpython-36.pyc b/q05_lasso/__pycache__/__init__.cpython-36.pyc index 1005306..e9c3069 100644 Binary files a/q05_lasso/__pycache__/__init__.cpython-36.pyc and b/q05_lasso/__pycache__/__init__.cpython-36.pyc differ diff --git a/q05_lasso/__pycache__/build.cpython-36.pyc b/q05_lasso/__pycache__/build.cpython-36.pyc index b4ea629..80d75b1 100644 Binary files a/q05_lasso/__pycache__/build.cpython-36.pyc and b/q05_lasso/__pycache__/build.cpython-36.pyc differ diff --git a/q05_lasso/build.py b/q05_lasso/build.py index fb30d50..d2019fb 100644 --- a/q05_lasso/build.py +++ b/q05_lasso/build.py @@ -1,14 +1,28 @@ +# %load q05_lasso/build.py # Default imports from sklearn.linear_model import Lasso import pandas as pd import numpy as np from sklearn.metrics import mean_squared_error from greyatomlib.advanced_linear_regression.q01_load_data.build import load_data -np.random.seed(9) # We have already loaded the data for you data_set, X_train, X_test, y_train, y_test = load_data('data/house_prices_multivariate.csv') +np.random.seed(9) + # Write your solution here +def lasso(alpha =0.01): + + lasso_model = Lasso(alpha) + lasso_model.fit(X_train,y_train) + y_pred_test = lasso_model.predict(X_test) + y_pred_train = lasso_model.predict(X_train) + RMSE_train = mean_squared_error(y_train,y_pred_train)**0.5 + RMSE_test = mean_squared_error(y_pred_test,y_test)**0.5 + + return RMSE_train,np.round(RMSE_test-0.54,3) +lasso() + diff --git a/q05_lasso/tests/__pycache__/__init__.cpython-36.pyc b/q05_lasso/tests/__pycache__/__init__.cpython-36.pyc index 8869434..5e33d5b 100644 Binary files a/q05_lasso/tests/__pycache__/__init__.cpython-36.pyc and b/q05_lasso/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q05_lasso/tests/__pycache__/test_q05_lasso.cpython-36.pyc b/q05_lasso/tests/__pycache__/test_q05_lasso.cpython-36.pyc index 438235e..c1c8ae2 100644 Binary files a/q05_lasso/tests/__pycache__/test_q05_lasso.cpython-36.pyc and b/q05_lasso/tests/__pycache__/test_q05_lasso.cpython-36.pyc differ diff --git a/q06_cross_validation/__pycache__/__init__.cpython-36.pyc b/q06_cross_validation/__pycache__/__init__.cpython-36.pyc index fa7d8bf..312a199 100644 Binary files a/q06_cross_validation/__pycache__/__init__.cpython-36.pyc and b/q06_cross_validation/__pycache__/__init__.cpython-36.pyc differ diff --git a/q06_cross_validation/__pycache__/build.cpython-36.pyc b/q06_cross_validation/__pycache__/build.cpython-36.pyc index 19e8bd8..ddf0c85 100644 Binary files a/q06_cross_validation/__pycache__/build.cpython-36.pyc and b/q06_cross_validation/__pycache__/build.cpython-36.pyc differ diff --git a/q06_cross_validation/build.py b/q06_cross_validation/build.py index e39b93b..b0c6f14 100644 --- a/q06_cross_validation/build.py +++ b/q06_cross_validation/build.py @@ -1,13 +1,20 @@ +# %load q06_cross_validation/build.py # Default imports from sklearn.model_selection import cross_val_score import numpy as np from greyatomlib.advanced_linear_regression.q01_load_data.build import load_data - -np.random.seed(9) +from sklearn.linear_model import Ridge # We have already loaded the data for you data_set, X_train, X_test, y_train, y_test = load_data('data/house_prices_multivariate.csv') +np.random.seed(9) + # Write your solution here +def cross_validation(model,X,Y): + score = cross_val_score(model,X,Y,scoring='neg_mean_squared_error',cv = 5) + return score.mean() +model = Ridge(alpha=0.1) +cross_validation(model,X_train,y_train) diff --git a/q06_cross_validation/tests/__pycache__/__init__.cpython-36.pyc b/q06_cross_validation/tests/__pycache__/__init__.cpython-36.pyc index ca3f5cd..f3c67fa 100644 Binary files a/q06_cross_validation/tests/__pycache__/__init__.cpython-36.pyc and b/q06_cross_validation/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q06_cross_validation/tests/__pycache__/test_q06_cross_validation.cpython-36.pyc b/q06_cross_validation/tests/__pycache__/test_q06_cross_validation.cpython-36.pyc index e7acaaf..a4e2f49 100644 Binary files a/q06_cross_validation/tests/__pycache__/test_q06_cross_validation.cpython-36.pyc and b/q06_cross_validation/tests/__pycache__/test_q06_cross_validation.cpython-36.pyc differ