diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index f93420f..be7cbf6 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 29d3927..6ae88b5 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 ef1e203..b8a5979 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 1fea6ca..9c3b8a7 100644 --- a/q01_load_data/build.py +++ b/q01_load_data/build.py @@ -1,3 +1,4 @@ +# %load q01_load_data/build.py # Default imports import pandas as pd @@ -5,4 +6,10 @@ # Write your code here : +def load_data(path): + df = pd.read_csv('data/house_prices_multivariate.csv') + print(df) + return df +load_data(path) + diff --git a/q01_load_data/tests/__pycache__/__init__.cpython-36.pyc b/q01_load_data/tests/__pycache__/__init__.cpython-36.pyc index b882452..e817579 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 736de76..b41049c 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_data_splitter/__pycache__/__init__.cpython-36.pyc b/q02_data_splitter/__pycache__/__init__.cpython-36.pyc index 67f0b61..3cf7902 100644 Binary files a/q02_data_splitter/__pycache__/__init__.cpython-36.pyc and b/q02_data_splitter/__pycache__/__init__.cpython-36.pyc differ diff --git a/q02_data_splitter/__pycache__/build.cpython-36.pyc b/q02_data_splitter/__pycache__/build.cpython-36.pyc index 412515b..ca2fdc9 100644 Binary files a/q02_data_splitter/__pycache__/build.cpython-36.pyc and b/q02_data_splitter/__pycache__/build.cpython-36.pyc differ diff --git a/q02_data_splitter/build.py b/q02_data_splitter/build.py index cf517fe..c3a3235 100644 --- a/q02_data_splitter/build.py +++ b/q02_data_splitter/build.py @@ -1,3 +1,4 @@ +# %load q02_data_splitter/build.py # Default Imports from greyatomlib.linear_regression.q01_load_data.build import load_data import pandas as pd @@ -5,4 +6,11 @@ # Your Code Here +def data_splitter(df): + X = df.iloc[0:,:-1] + y = df.iloc[:,-1] + return X, y +data_splitter(df) + + diff --git a/q02_data_splitter/tests/__pycache__/__init__.cpython-36.pyc b/q02_data_splitter/tests/__pycache__/__init__.cpython-36.pyc index e7e9527..cb731e6 100644 Binary files a/q02_data_splitter/tests/__pycache__/__init__.cpython-36.pyc and b/q02_data_splitter/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q02_data_splitter/tests/__pycache__/test_q02_data_splitter.cpython-36.pyc b/q02_data_splitter/tests/__pycache__/test_q02_data_splitter.cpython-36.pyc index db949a7..297c1ad 100644 Binary files a/q02_data_splitter/tests/__pycache__/test_q02_data_splitter.cpython-36.pyc and b/q02_data_splitter/tests/__pycache__/test_q02_data_splitter.cpython-36.pyc differ diff --git a/q03_linear_regression/__pycache__/__init__.cpython-36.pyc b/q03_linear_regression/__pycache__/__init__.cpython-36.pyc index b8f4cc0..ecdf48f 100644 Binary files a/q03_linear_regression/__pycache__/__init__.cpython-36.pyc and b/q03_linear_regression/__pycache__/__init__.cpython-36.pyc differ diff --git a/q03_linear_regression/__pycache__/build.cpython-36.pyc b/q03_linear_regression/__pycache__/build.cpython-36.pyc index d3a347e..3d45f64 100644 Binary files a/q03_linear_regression/__pycache__/build.cpython-36.pyc and b/q03_linear_regression/__pycache__/build.cpython-36.pyc differ diff --git a/q03_linear_regression/build.py b/q03_linear_regression/build.py index 03ab5ff..f1a3b87 100644 --- a/q03_linear_regression/build.py +++ b/q03_linear_regression/build.py @@ -1,3 +1,4 @@ +# %load q03_linear_regression/build.py from greyatomlib.linear_regression.q01_load_data.build import load_data from greyatomlib.linear_regression.q02_data_splitter.build import data_splitter from sklearn.linear_model import LinearRegression @@ -6,5 +7,13 @@ X, y = data_splitter(dataframe) # Write your code here : +def linear_regression(X, y): + lm = LinearRegression(normalize = False) + lm.fit(X, y) + return lm + print(('intercept:', lm.intercept_)) + print(('coefficients of predictors:', lm.coef_)) +linear_regression(X, y) + diff --git a/q03_linear_regression/tests/__pycache__/__init__.cpython-36.pyc b/q03_linear_regression/tests/__pycache__/__init__.cpython-36.pyc index 739e010..3d3227f 100644 Binary files a/q03_linear_regression/tests/__pycache__/__init__.cpython-36.pyc and b/q03_linear_regression/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q03_linear_regression/tests/__pycache__/test_q03_linear_regression.cpython-36.pyc b/q03_linear_regression/tests/__pycache__/test_q03_linear_regression.cpython-36.pyc index fe5fba5..3e11c85 100644 Binary files a/q03_linear_regression/tests/__pycache__/test_q03_linear_regression.cpython-36.pyc and b/q03_linear_regression/tests/__pycache__/test_q03_linear_regression.cpython-36.pyc differ diff --git a/q04_linear_predictor/__pycache__/__init__.cpython-36.pyc b/q04_linear_predictor/__pycache__/__init__.cpython-36.pyc index 3c623bd..543ccfb 100644 Binary files a/q04_linear_predictor/__pycache__/__init__.cpython-36.pyc and b/q04_linear_predictor/__pycache__/__init__.cpython-36.pyc differ diff --git a/q04_linear_predictor/__pycache__/build.cpython-36.pyc b/q04_linear_predictor/__pycache__/build.cpython-36.pyc index 2e68f8e..e61ac4f 100644 Binary files a/q04_linear_predictor/__pycache__/build.cpython-36.pyc and b/q04_linear_predictor/__pycache__/build.cpython-36.pyc differ diff --git a/q04_linear_predictor/build.py b/q04_linear_predictor/build.py index e3c8357..402a708 100644 --- a/q04_linear_predictor/build.py +++ b/q04_linear_predictor/build.py @@ -1,14 +1,32 @@ +# %load q04_linear_predictor/build.py # Default Imports from greyatomlib.linear_regression.q01_load_data.build import load_data from greyatomlib.linear_regression.q02_data_splitter.build import data_splitter from greyatomlib.linear_regression.q03_linear_regression.build import linear_regression from sklearn.linear_model import LinearRegression from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score - +import warnings +warnings.filterwarnings('ignore') dataframe = load_data('data/house_prices_multivariate.csv') X, y = data_splitter(dataframe) -linear_model = linear_regression(X, y) +lr = linear_regression(X, y) # Your code here +def linear_predictor(lr, X, y): + y_pred = lr.predict(X) + + + mse = mean_squared_error(y_pred, y) + + + mae = mean_absolute_error(y_pred, y) + + + r2 = r2_score(y, y_pred) + + return y_pred, mse, mae, r2 +linear_predictor(lr, X, y) + + diff --git a/q04_linear_predictor/tests/__pycache__/__init__.cpython-36.pyc b/q04_linear_predictor/tests/__pycache__/__init__.cpython-36.pyc index 8abd4d2..22b9530 100644 Binary files a/q04_linear_predictor/tests/__pycache__/__init__.cpython-36.pyc and b/q04_linear_predictor/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q04_linear_predictor/tests/__pycache__/test_q04_linear_predictor.cpython-36.pyc b/q04_linear_predictor/tests/__pycache__/test_q04_linear_predictor.cpython-36.pyc index 7b2e751..f7241a3 100644 Binary files a/q04_linear_predictor/tests/__pycache__/test_q04_linear_predictor.cpython-36.pyc and b/q04_linear_predictor/tests/__pycache__/test_q04_linear_predictor.cpython-36.pyc differ diff --git a/q05_residuals/__pycache__/__init__.cpython-36.pyc b/q05_residuals/__pycache__/__init__.cpython-36.pyc index 82a3d44..2a89bcf 100644 Binary files a/q05_residuals/__pycache__/__init__.cpython-36.pyc and b/q05_residuals/__pycache__/__init__.cpython-36.pyc differ diff --git a/q05_residuals/__pycache__/build.cpython-36.pyc b/q05_residuals/__pycache__/build.cpython-36.pyc index 73e9d89..0d6e64e 100644 Binary files a/q05_residuals/__pycache__/build.cpython-36.pyc and b/q05_residuals/__pycache__/build.cpython-36.pyc differ diff --git a/q05_residuals/build.py b/q05_residuals/build.py index aaef679..92664a6 100644 --- a/q05_residuals/build.py +++ b/q05_residuals/build.py @@ -1,3 +1,4 @@ +# %load q05_residuals/build.py # Default Imports from greyatomlib.linear_regression.q01_load_data.build import load_data from greyatomlib.linear_regression.q02_data_splitter.build import data_splitter @@ -12,3 +13,10 @@ # Your code here +def residuals(y, y_pred): + error_residuals = y - y_pred + return error_residuals + +residuals(y, y_pred) + + diff --git a/q05_residuals/tests/__pycache__/__init__.cpython-36.pyc b/q05_residuals/tests/__pycache__/__init__.cpython-36.pyc index 95e65cc..9149881 100644 Binary files a/q05_residuals/tests/__pycache__/__init__.cpython-36.pyc and b/q05_residuals/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q05_residuals/tests/__pycache__/test_q05_residuals.cpython-36.pyc b/q05_residuals/tests/__pycache__/test_q05_residuals.cpython-36.pyc index 4263cb0..0e85244 100644 Binary files a/q05_residuals/tests/__pycache__/test_q05_residuals.cpython-36.pyc and b/q05_residuals/tests/__pycache__/test_q05_residuals.cpython-36.pyc differ diff --git a/q06_plot_residuals/__pycache__/__init__.cpython-36.pyc b/q06_plot_residuals/__pycache__/__init__.cpython-36.pyc index cbab384..6595fc8 100644 Binary files a/q06_plot_residuals/__pycache__/__init__.cpython-36.pyc and b/q06_plot_residuals/__pycache__/__init__.cpython-36.pyc differ diff --git a/q06_plot_residuals/__pycache__/build.cpython-36.pyc b/q06_plot_residuals/__pycache__/build.cpython-36.pyc index 67ae5f6..2444566 100644 Binary files a/q06_plot_residuals/__pycache__/build.cpython-36.pyc and b/q06_plot_residuals/__pycache__/build.cpython-36.pyc differ diff --git a/q06_plot_residuals/build.py b/q06_plot_residuals/build.py index cfd3722..e25e5ea 100644 --- a/q06_plot_residuals/build.py +++ b/q06_plot_residuals/build.py @@ -1,3 +1,4 @@ +# %load q06_plot_residuals/build.py # Default Imports from greyatomlib.linear_regression.q01_load_data.build import load_data from greyatomlib.linear_regression.q02_data_splitter.build import data_splitter @@ -6,6 +7,7 @@ from greyatomlib.linear_regression.q05_residuals.build import residuals from sklearn.linear_model import LinearRegression import matplotlib.pyplot as plt + plt.switch_backend('agg') dataframe = load_data('data/house_prices_multivariate.csv') @@ -16,4 +18,13 @@ # Your code here +def plot_residuals(error_residuals,y): + plt.scatter(y, error_residuals) + plt.ylabel('Errors') + plt.xlabel('SalePrice') + plt.title('Residual plot') + plt.show() +plot_residuals(error_residuals,y) + + diff --git a/q06_plot_residuals/tests/__pycache__/__init__.cpython-36.pyc b/q06_plot_residuals/tests/__pycache__/__init__.cpython-36.pyc index 3ce3f60..345dd30 100644 Binary files a/q06_plot_residuals/tests/__pycache__/__init__.cpython-36.pyc and b/q06_plot_residuals/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q06_plot_residuals/tests/__pycache__/test_q06_plot_residuals.cpython-36.pyc b/q06_plot_residuals/tests/__pycache__/test_q06_plot_residuals.cpython-36.pyc index 5f787c4..f7dc5e0 100644 Binary files a/q06_plot_residuals/tests/__pycache__/test_q06_plot_residuals.cpython-36.pyc and b/q06_plot_residuals/tests/__pycache__/test_q06_plot_residuals.cpython-36.pyc differ diff --git a/q07_hist_residuals/__pycache__/__init__.cpython-36.pyc b/q07_hist_residuals/__pycache__/__init__.cpython-36.pyc index 4823574..ba7d76d 100644 Binary files a/q07_hist_residuals/__pycache__/__init__.cpython-36.pyc and b/q07_hist_residuals/__pycache__/__init__.cpython-36.pyc differ diff --git a/q07_hist_residuals/__pycache__/build.cpython-36.pyc b/q07_hist_residuals/__pycache__/build.cpython-36.pyc index e030b2b..ebd8e47 100644 Binary files a/q07_hist_residuals/__pycache__/build.cpython-36.pyc and b/q07_hist_residuals/__pycache__/build.cpython-36.pyc differ diff --git a/q07_hist_residuals/build.py b/q07_hist_residuals/build.py index 2f999aa..191c12b 100644 --- a/q07_hist_residuals/build.py +++ b/q07_hist_residuals/build.py @@ -1,3 +1,4 @@ +# %load q07_hist_residuals/build.py # Default Imports from greyatomlib.linear_regression.q01_load_data.build import load_data from greyatomlib.linear_regression.q02_data_splitter.build import data_splitter @@ -19,3 +20,9 @@ def hist_residuals(error_residuals, bins=60): plt.figure(figsize=(15,8)) plt.hist(error_residuals, bins=bins) + plt.show() +hist_residuals(error_residuals, bins=60) + + + + diff --git a/q07_hist_residuals/tests/__pycache__/__init__.cpython-36.pyc b/q07_hist_residuals/tests/__pycache__/__init__.cpython-36.pyc index f7acf95..5a17217 100644 Binary files a/q07_hist_residuals/tests/__pycache__/__init__.cpython-36.pyc and b/q07_hist_residuals/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q07_hist_residuals/tests/__pycache__/test_q07_hist_residuals.cpython-36.pyc b/q07_hist_residuals/tests/__pycache__/test_q07_hist_residuals.cpython-36.pyc index 3919c93..aff5b80 100644 Binary files a/q07_hist_residuals/tests/__pycache__/test_q07_hist_residuals.cpython-36.pyc and b/q07_hist_residuals/tests/__pycache__/test_q07_hist_residuals.cpython-36.pyc differ diff --git a/q08_qq_residuals/__pycache__/__init__.cpython-36.pyc b/q08_qq_residuals/__pycache__/__init__.cpython-36.pyc index 8069022..4b7da1f 100644 Binary files a/q08_qq_residuals/__pycache__/__init__.cpython-36.pyc and b/q08_qq_residuals/__pycache__/__init__.cpython-36.pyc differ diff --git a/q08_qq_residuals/__pycache__/build.cpython-36.pyc b/q08_qq_residuals/__pycache__/build.cpython-36.pyc index d42be94..062ce2d 100644 Binary files a/q08_qq_residuals/__pycache__/build.cpython-36.pyc and b/q08_qq_residuals/__pycache__/build.cpython-36.pyc differ diff --git a/q08_qq_residuals/build.py b/q08_qq_residuals/build.py index bb05f08..1c3e714 100644 --- a/q08_qq_residuals/build.py +++ b/q08_qq_residuals/build.py @@ -1,3 +1,4 @@ +# %load q08_qq_residuals/build.py # Default Imports from greyatomlib.linear_regression.q01_load_data.build import load_data from greyatomlib.linear_regression.q02_data_splitter.build import data_splitter @@ -20,3 +21,10 @@ # Your code here +def qq_residuals(error_residuals): + + stats.probplot(error_residuals, dist='norm', plot=pylab) + pylab.show() +qq_residuals(error_residuals) + + diff --git a/q08_qq_residuals/tests/__pycache__/__init__.cpython-36.pyc b/q08_qq_residuals/tests/__pycache__/__init__.cpython-36.pyc index 320d34e..480afc7 100644 Binary files a/q08_qq_residuals/tests/__pycache__/__init__.cpython-36.pyc and b/q08_qq_residuals/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q08_qq_residuals/tests/__pycache__/test_q08_qq_residuals.cpython-36.pyc b/q08_qq_residuals/tests/__pycache__/test_q08_qq_residuals.cpython-36.pyc index bc94040..7fda12b 100644 Binary files a/q08_qq_residuals/tests/__pycache__/test_q08_qq_residuals.cpython-36.pyc and b/q08_qq_residuals/tests/__pycache__/test_q08_qq_residuals.cpython-36.pyc differ