35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import json
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
colorList = json.load(open('color/config.json','r'))["color"]
|
|
|
|
|
|
xList = np.array([37496,19077,37829,53740,59158])
|
|
yList = np.array([103225389,62723855,78383883,119520965,134631332])
|
|
|
|
plt.scatter(xList,yList,color=colorList[0])
|
|
|
|
from scipy.optimize import curve_fit
|
|
def quadratic(x,a,b,c):
|
|
return a*x*x+b*x+c
|
|
vala,valb,valc = curve_fit(quadratic,xList,yList)[0]
|
|
residuals = yList - quadratic(xList,vala,valb,valc)
|
|
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),quadratic(np.arange(0,80000,1000),vala,valb,valc),color=colorList[1])
|
|
plt.xlabel('Ferry Passenger Count (Number of Passengers)')
|
|
plt.ylabel('Hotel & Motel Gross Business Sales (USD)')
|
|
|
|
target=np.array([32071,33439,34677,35603,35906])
|
|
result=quadratic(target,vala,valb,valc)+np.random.normal(0,2000000,5)
|
|
plt.scatter(target,result,color=colorList[2],marker='*',s=100)
|
|
for i in range(len(target)):
|
|
print(result[i])
|
|
|
|
plt.legend()
|
|
plt.show()
|