-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorFunction.py
More file actions
37 lines (28 loc) · 1.06 KB
/
errorFunction.py
File metadata and controls
37 lines (28 loc) · 1.06 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
import matplotlib.pyplot as plt
import numpy as np
from helper import *
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error
x, y = regression_data()
print("X: ", x.shape)
print("Y: ", y.shape)
plt.scatter(x, y, color= "blue")
plt.show()
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state = 42)
linear_model = LinearRegression()
linear_model.fit(x_train, y_train) #training
score = linear_model.score(x_test, y_test) #testing
def compute_error_mae(y_true, y_pred):
ret_mae = mean_absolute_error(y_true, y_pred)
return ret_mae
def compute_error_mse(y_true, y_pred):
ret_mse = mean_squared_error(y_true, y_pred)
return ret_mse
y_predict = linear_model.predict(x_test)
mae = compute_error_mae(y_test, y_predict)
mse = compute_error_mse(y_test, y_predict)
print("Linear Model Score (MAE): ", mae)
print("Linear Model Score (MSE): ", mse)
print("Linear Model Score (R2): ", score)