37 lines
833 B
Python
37 lines
833 B
Python
import json
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
colorList = json.load(open('color/config.json','r'))["color"]
|
|
|
|
import csv
|
|
|
|
with open('data/passenger.csv', 'r') as f:
|
|
reader = csv.reader(f)
|
|
header = next(reader)
|
|
data = [row for row in reader]
|
|
|
|
data = np.array(data).astype(int).T
|
|
|
|
xList = data[1]
|
|
yList = data[2]/data[1]
|
|
|
|
plt.scatter(xList,yList,color=colorList[0])
|
|
|
|
from scipy.optimize import curve_fit
|
|
def linear(x,k,b):
|
|
return k*x+b
|
|
valk,valb = curve_fit(linear,xList,yList)[0]
|
|
residuals = yList - linear(xList,valk,valb)
|
|
ss_res = np.sum(residuals**2)
|
|
ss_tot = np.sum((yList-np.mean(yList))**2)
|
|
r_squared = 1 - (ss_res / ss_tot)
|
|
print("R-squared:", r_squared)
|
|
|
|
plt.plot(np.arange(0,80000,1000),linear(np.arange(0,80000,1000),valk,valb),color=colorList[1])
|
|
|
|
bar_width = 0.25
|
|
|
|
plt.legend()
|
|
plt.show()
|