-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinear_regresion_sales.py
107 lines (75 loc) · 1.62 KB
/
linear_regresion_sales.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import math as m
import numpy as np
''' include the proper directory of the file'''
f=open('C:\\Users\\user\\Desktop\\important\\csv\\sales.csv','r')
w=[]
q=[]
e=f.read().splitlines()
''' CHANGE THE NUMBER WITHIN THIRD BRACKETS FOR APPROPRIATE VALUE OF INDEPENDENT VARIABLE AND DEPENDENT VARIABLES '''
for i in range(1,len(e)):
n=e[i]
z=n.split(',')
w.append(z[8])
q.append(z[13])
sum=0
sum1=0
''' MEANX'''
for i in w:
sum+=float(i)
size=np.size(w)
print('meanx')
print('-'*46)
meanx=sum/size
print(meanx)
'''MEANY'''
for i in q:
sum1+=float(i)
print('meany')
print('-'*46)
meany=sum1/size
print(meany)
print('-'*46)
for i in range(2):
m1=0
m2=0
for i,j in zip(w,q):
a=(float(i)-meanx)*(float(j)-meany)
b=m.pow((float(i)-meanx),(2))
m1=m1+a
m2+=b
break
m=m1/m2
print("THE VALUE OF 'M' IS")
print(float(m))
c=((meany)-((meanx)*(float(m))))
print("THE VALUE OF 'C' IS")
print(c)
print('-'*46)
y=[]
for j in range(2):
for i in w:
r=(m)*float(i)+float(c)
y.append(r)
print(y)
break
''' DATA TESTING'''
print('-'*46)
print(' TESTING DATA')
h=int(input('enter the number of points'))
k=[]
for i in range(h):
k.append(float(input(' enter point')))
for i in k:
print('MY ASSUMPTIONS TO THE REQUEST IS....')
print((m)*float(i)+float(c))
''' COST FUNCTION'''
print('-'*46)
print(' COST FUNCTION')
m=5
sum2=0
for i,j in zip(y,q):
s=i-float(j)
c=np.power(s,2)
sum2+=c
j=sum2/(2*m)
print(j)