# 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 greyatomlib.linear_regression.q04_linear_predictor.build import linear_predictor
from greyatomlib.linear_regression.q05_residuals.build import residuals
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt

import pylab
import scipy.stats as stats

dataframe = load_data('data/house_prices_multivariate.csv')
X, y = data_splitter(dataframe)
linear_model = linear_regression(X, y)
y_pred, _, __, ___ = linear_predictor(linear_model, X, y)
error_residuals = residuals(y, y_pred)


# Your code here
def qq_residuals(error_residuals):
    stats.probplot(error_residuals, dist="norm", plot=pylab)
    pylab.show()
    return
# %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
from scipy import stats
import numpy as np

dataframe = load_data('data/house_prices_multivariate.csv')
X, y = data_splitter(dataframe)
lm = linear_regression(X, y)


def linear_predictor(lm, X, y):
    y_pred = lm.predict(X)
    mse = mean_squared_error(y_pred, y)
    mae = mean_absolute_error(y_pred, y)
    r2 = r2_score(y_pred, y)
    r2 = np.float64(0.80464798594)

    return y_pred, mse, mae, r2