-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathregression.py
38 lines (29 loc) · 1.44 KB
/
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
37
38
#Developing a Pairs Trading strategy for the Indian Banking sector
#Simple regression line plotting between scrips of Axis Bank and ICICI Bank
#******************************************************************
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
datasets = pd.read_csv('AXIS.NS.csv') #Importing the datasets
datasets = pd.read_csv('ICICI.NS.csv')
X = datasets.iloc[:, :-1].values
Y = datasets.iloc[:, 1].values
from sklearn.model_selection import train_test_split #Splitting the dataset into the Training set and Test set
X_Train, X_Test, Y_Train, Y_Test = train_test_split(X, Y, test_size = 1/3, random_state = 0)
#Fitting simple Linear Regression to the training set
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_Train, Y_Train)
Y_Pred = regressor.predict(X_Test) #Predicting the Test set result
plt.scatter(X_Train, Y_Train, color = 'blue') #Visualising the Training set results
plt.plot(X_Train, regressor.predict(X_Train), color = 'yellow')
plt.title('Price AXISBANK vs. ICICIBANK (Training Set)')
plt.xlabel('Price change')
plt.ylabel('Regression coefficient')
plt.show()
plt.scatter(X_Test, Y_Test, color = 'blue') #Visualising the Test set results
plt.plot(X_Train, regressor.predict(X_Train), color = 'yellow')
plt.title('Price AXISBANK vs. ICICIBANK (Test Set)')
plt.xlabel('Price change')
plt.ylabel('Regression')
plt.show()