Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

import pandas as pd

from matplotlib import pyplot as plt

from sklearn.linear_model import LinearRegression

from scipy.stats import linregress

data = pd.read_csv('_.csv')

data

x = data.Quantity

y = data.UnitPrice

plt.plot(data.Quantity, data.UnitPrice)

plt.xlabel('Quantity')

plt.ylabel('UnitPrice')

X = data.iloc[:, 0].values.reshape(-1, 1) # values converts it into a numpy array

Y = data.iloc[:, 1].values.reshape(-1, 1) # -1 means that calculate the dimension of rows, but have 1
column

linear_regressor = LinearRegression() # create object for the class

linear_regressor.fit(X, Y) # perform linear regression

Y_pred = linear_regressor.predict(X) # make predictions

plt.scatter(X, Y)

plt.plot(X, Y_pred, color='red')

plt.show()

data.corr(method = "pearson")

m = linear_regressor.coef_

print(m)
c = linear_regressor.intercept_

print(c)

predict = 100

y = c + m * predict

print(y)

You might also like