-
Notifications
You must be signed in to change notification settings - Fork 0
/
accuracy_of_data
61 lines (48 loc) · 1.39 KB
/
accuracy_of_data
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
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
plt.rcParams ['figure.figsize'] = (20.0,10.0)
#for popularirty
print("WELCOME_TO_BIT_MESRA_PHYSICS_LAB")
print("Created by SHIVAM KUMAR ECE K19 batch")
#collecting X and Y
n = int(input("Enter number of elements : "))
X = list(map(float,input("\nEnter the X-co ordinates : ").strip().split()))[:n]
print("\nValues of X are - ", X)
Y = list(map(float,input("\nEnter the Y-co ordinates: ").strip().split()))[:n]
print("\nValues of Y are - ", Y)
#Mean X and Y
mean_x = np.mean(X)
mean_y = np.mean(Y)
# Total no. of values
m = len(X)
#Using the formula to calculate b1 and b2
numer = 0
denom = 0
for i in range(m):
numer +=(X[i] - mean_x) * (Y[i] - mean_y)
denom +=(X[i] - mean_x) **2
b1 = numer / denom
b0 = mean_y - (b1 * mean_x)
#print coefficient
print(b1,b0)
#plotting values and regression line
max_x = np.max(X) + 100
min_x = np.min(X) - 100
#Calculating line values x and y
x = np.linspace(min_x, max_x, 1000)
y = b0 + b1 * x
#plotting Line
plt.plot(x, y ,color='#58b970', label='Regression Line')
#Plotting scatter points
plt.scatter(X, Y, c='#ef5423', label='Scatter plot')
#title of graph
s1=str(input("Enter the title: "))
plt.title(s1.upper(), color='r')
x2=str(input("Enter the name of X-axis: "))
plt.xlabel(x2)
y2=str(input("Enter the name of Y-axis: "))
plt.ylabel(y2)
plt.legend()
plt.show()