-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluate.py
More file actions
63 lines (45 loc) · 1.49 KB
/
evaluate.py
File metadata and controls
63 lines (45 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import warnings
warnings.filterwarnings("ignore")
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from scipy.stats import pearsonr, spearmanr
from env import get_db_url
import wrangle as w
import prepare as p
import matplotlib as mpl
mpl.rcParams["axes.formatter.useoffset"] = False
#import sklearn mean_square_error
from sklearn.metrics import mean_squared_error
#import r2_score from sklearn
from sklearn.metrics import r2_score
import sklearn.preprocessing
def plot_residuals(y, yhat):
residuals = y - yhat
plt.scatter(x=y, y=residuals)
plt.xlabel('Home Value')
plt.ylabel('Residuals')
plt.title('Residual vs Home Value Plot')
plt.show()
def regression_errors(y, yhat):
MSE = mean_squared_error(y, yhat)
SSE = MSE * len(y)
RMSE = MSE**.5
ESS = ((yhat - y.mean())**2).sum()
TSS = ESS + SSE
return SSE, ESS, TSS, MSE, RMSE
def baseline_mean_errors(y):
baseline = np.repeat(y.mean(), len(y))
MSE = mean_squared_error(y, baseline)
SSE = MSE * len(y)
RMSE = MSE**.5
return SSE, MSE, RMSE
def better_than_baseline(y, yhat):
SSE, ESS, TSS, MSE, RMSE = regression_errors(y, yhat)
SSE_baseline, MSE_baseline, RMSE_baseline = baseline_mean_errors(y)
if SSE < SSE_baseline:
print('My OSL model performs better than baseline')
else:
print('My OSL model performs worse than baseline. :( )')