-
Notifications
You must be signed in to change notification settings - Fork 1
/
03 - Linear Regression.py
36 lines (28 loc) · 1.13 KB
/
03 - Linear Regression.py
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
import numpy as np
import pandas as pd
import sklearn
from sklearn import linear_model
import pickle
# Data Preparation
data = pd.read_csv("student-mat.csv", sep=";")
data = data[["G1", "G2", "G3", "studytime", "failures", "absences"]]
predict = "G3"
x = np.array(data.drop([predict], 1))
y = np.array(data[predict])
x_train, x_test, y_train, y_test = sklearn.model_selection.train_test_split(x, y, test_size=0.1)
##############################
pickle_in = open("studentGradeModel.pickle", "rb")
linear = pickle.load(pickle_in)
###############################
accuracy = linear.score(x_test,y_test)
print("Model Accuracy: ", accuracy)
print("Coefficient: ", linear.coef_) #We have a 5 dimensional space here so we have 5 Coefficients! (our line starting position depending on 5 axis )
print("Intercept: ", linear.intercept_) # y
print("\n\n#####################################")
predictions = linear.predict(x_test)
for i in range(len(predictions)):
print(f"Data #{i+1}")
print("Model Prediction: ", predictions[i])
print("Input Data: ", x_test[i])
print("Real Label: ", y_test[i])
print("#####################################")