diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index ebbd53a..799e8aa 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..53db5d2 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..9e08e28 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..ee7d6d2 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' +def load_data(path,test_size=0.33,random_state=9): + data=pd.read_csv(path) + X = data.iloc[:,:-1] + y = data['SalePrice'] + X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=9) + return(data,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..721d7bb 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..aab16b3 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/q03_polynomial/__pycache__/__init__.cpython-36.pyc b/q03_polynomial/__pycache__/__init__.cpython-36.pyc index aa42922..8c2f062 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..182b868 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..c2e3cf5 100644 --- a/q03_polynomial/build.py +++ b/q03_polynomial/build.py @@ -1,11 +1,20 @@ -# 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 +# %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 +import matplotlib.pyplot as plt +import numpy as np + +def polynomial(power=5,random_state=9): + data_set, X_train, X_test, y_train, y_test = load_data('data/house_prices_multivariate.csv') + cols=['OverallQual','GrLivArea','GarageCars','GarageArea'] + poly_model = make_pipeline(PolynomialFeatures(5,include_bias=False),LinearRegression()) + poly_model.fit(X_train[cols], y_train.reshape(-1,1)) + ypred = poly_model.predict(np.array([4, 5, 6, 7]).reshape(1, -1)) + return(poly_model) +polynomial(power=5,random_state=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') -# Write your solution here diff --git a/q03_polynomial/tests/__pycache__/__init__.cpython-36.pyc b/q03_polynomial/tests/__pycache__/__init__.cpython-36.pyc index 6e20876..df74a73 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..88671c2 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..67d6efd 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..8966890 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..327d779 100644 --- a/q04_ridge/build.py +++ b/q04_ridge/build.py @@ -1,15 +1,24 @@ +# %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') +p=np.random.seed(9) +def ridge(alpha=0.01): + ridge_model=Ridge(alpha=0.01, normalize=True, random_state=9) + ridge_model.fit(X_train, y_train) + y_pred = ridge_model.predict(X_test) + y_trainp=ridge_model.predict(X_train) + rmsetest=np.sqrt(mean_squared_error(y_test, y_pred)) + rmsetrain=np.sqrt(mean_squared_error(y_train, y_trainp)) + return(rmsetrain,rmsetest,ridge_model) + -# 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..0e25cd0 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..fcece82 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..eac0adc 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..549b896 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..d40e38e 100644 --- a/q05_lasso/build.py +++ b/q05_lasso/build.py @@ -1,14 +1,27 @@ +# %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) + +def lasso(alpha=0.01): + Lasso_model=Lasso(alpha=0.01, normalize=True, random_state=9) + Lasso_model.fit(X_train, y_train) + y_pred = Lasso_model.predict(X_test) + y_trainp=Lasso_model.predict(X_train) + rmsetest=np.sqrt(mean_squared_error(y_test, y_pred)) + rmsetrain=np.sqrt(mean_squared_error(y_train, y_trainp)) + return(rmsetrain,rmsetest) + # Write your solution here + + diff --git a/q05_lasso/tests/__pycache__/__init__.cpython-36.pyc b/q05_lasso/tests/__pycache__/__init__.cpython-36.pyc index 8869434..d783a3c 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..67cd2a2 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..23466b4 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..bf4fafd 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..85df2e6 100644 --- a/q06_cross_validation/build.py +++ b/q06_cross_validation/build.py @@ -1,13 +1,18 @@ +# %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) -# We have already loaded the data for you +from sklearn.linear_model import Ridge +from sklearn.linear_model import Lasso data_set, X_train, X_test, y_train, y_test = load_data('data/house_prices_multivariate.csv') +Model=Ridge(alpha=0.1) +# We have already loaded the data for you +def cross_validation(Model, X_train, y_train): + scores = cross_val_score(Ridge(alpha=0.1),X_train,y_train,scoring='neg_mean_squared_error',cv=5) + return(scores.mean()) -# Write your solution here +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..da00dd9 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..52128b3 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