-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregresion_uni.py
51 lines (37 loc) · 1.19 KB
/
regresion_uni.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import numpy as num
import matplotlib.pyplot as plt
import pandas as pd
#Reading the given dataset#
dataset = pd.read_excel('blood.csv.xlsx')
X = dataset.iloc[2:, 1].values
y = dataset.iloc[2:, -1].values
y=y.reshape(-1,1)#converting one-dimension to 2-dimension#
X = X.reshape(-1, 1)
plt.scatter(X, y)
plt.show()
#spliting the data for train and test #
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X, y, test_size=0.2, random_state=0)
#applying the linear regression#
from sklearn.linear_model import LinearRegression
lin_reg = LinearRegression()
lin_reg.fit(X_train,y_train)
#Predicting the required results#
y_predict = lin_reg.predict(X_test)
#ploting the required result#
plt.scatter(X,y)
plt.plot(X_test,y_test, 'y')
plt.plot(X_test,y_predict ,'r')
plt.show()
lin_reg.score(X_test,y_test)
lin_reg.score(X_train,y_train)
lin_reg.score(X,y)
plt.scatter(X_train, y_train)
plt.plot(X_train, lin_reg.predict(X_train), c = "r")
plt.show()
plt.scatter(X_test, y_test)
plt.plot(X_test, lin_reg.predict(X_test), c = "r")
plt.show()
plt.scatter(X, y)
plt.plot(X, lin_reg.predict(X), c = "r")
plt.show()