-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBIC Finder.py
55 lines (44 loc) · 1.14 KB
/
BIC Finder.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
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from scipy.stats import linregress
import numpy as np
import math
lin = LinearRegression()
File = './PositiveData.csv'
raw = pd.read_csv(File, delimiter="\t")
#print(raw)
x = raw.iloc[:,0]
y = raw.iloc[:,1]
# print(y)
n = len(x)
plt.plot(x,y,'o')
p1 = np.polyfit(x,y,1)
p2 = np.polyfit(x,y,2)
p3 = np.polyfit(x,y,3)
p4 = np.polyfit(x,y,4)
p5 = np.polyfit(x,y,5)
p6 = np.polyfit(x,y,6)
plt.plot(x,y,'o')
xp = np.linspace(18,100,1000)
#plt.plot(xp,np.polyval(p1,xp),'r-')
#plt.plot(xp,np.polyval(p2,xp),'b--')
#plt.plot(xp,np.polyval(p3,xp),'m:')
plt.plot(xp,np.polyval(p4,xp))
#plt.plot(xp,np.polyval(p5,xp))
#plt.plot(xp,np.polyval(p6,xp))
# yfit = p1[0] * x + p1[1]
polyDegree=[p1,p2,p3,p4,p5,p6]
BIC = []
for k, p in enumerate(polyDegree):
Yfit = np.polyval(p,x)
yresid= y - Yfit
SSresid = np.sum(yresid**2)
#print(SSresid)
BIC.append(n*math.log(SSresid)+k*math.log(n))
slope,intercept,r_value,p_value,std_err = linregress(x,y)
plt.show()
print(BIC)
plt.plot((1,2,3,4,5,6),BIC,'o')
plt.show()