something new
This commit is contained in:
parent
50e633ff04
commit
f23fc110ca
@ -1,11 +1,11 @@
|
||||
Year,Ferry Passenger,Hotel & Motel Gross Business Sales,population
|
||||
2014,72187,32071,33256
|
||||
2015,65101,33439,33445
|
||||
2016,59194,34677,33081
|
||||
2017,57144,35603,32729
|
||||
2018,53920,35906,32664
|
||||
2019,41559,37496,32544
|
||||
2020,10987,19077,32255
|
||||
2021,25299,37829,32239
|
||||
2022,35683,53740,31834
|
||||
2023,41469,59158,31549
|
||||
Year,Cruise Ship Visitation,Ferry Passenger,Air Passenger,Hotel & Motel Gross Business Sales,total earnings,local residents
|
||||
2014,953100,72187,307742,32071,,33256
|
||||
2015,982500,65101,331079,33439,,33445
|
||||
2016,1015100,59194,339279,34677,,33081
|
||||
2017,1072300,57144,345454,35603,,32729
|
||||
2018,1151100,53920,358388,35906,,32664
|
||||
2019,1305700,41559,365349,37496,1032253389,32544
|
||||
2020,37,10987,154292,19077,62723855,32255
|
||||
2021,115800,25299,284039,37829,78383883,32239
|
||||
2022,1167194,35683,359312,53740,119520965,31834
|
||||
2023,1638902,41469,354905,59158,134631332,31549
|
||||
|
17
data/passenger.csv.bak
Normal file
17
data/passenger.csv.bak
Normal file
@ -0,0 +1,17 @@
|
||||
Year,Cruise Ship Visitation,Ferry Passenger,Air Passenger,Hotel & Motel Gross Business Sales,total earnings,local residents
|
||||
2008,,,291620,,,
|
||||
2009,,,264004,,,
|
||||
2010,,,285720,,,
|
||||
2011,,,291069,,,
|
||||
2012,931000,,288311,,,
|
||||
2013,985700,,289993,,,33138
|
||||
2014,953100,72187,307742,32071,,33256
|
||||
2015,982500,65101,331079,33439,,33445
|
||||
2016,1015100,59194,339279,34677,,33081
|
||||
2017,1072300,57144,345454,35603,,32729
|
||||
2018,1151100,53920,358388,35906,,32664
|
||||
2019,1305700,41559,365349,37496,1032253389,32544
|
||||
2020,37,10987,154292,19077,62723855,32255
|
||||
2021,115800,25299,284039,37829,78383883,32239
|
||||
2022,1167194,35683,359312,53740,119520965,31834
|
||||
2023,1638902,41469,354905,59158,134631332,31549
|
||||
53
optimizer1.py
Normal file
53
optimizer1.py
Normal file
@ -0,0 +1,53 @@
|
||||
import math
|
||||
import json
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
colorList = json.load(open('color/config.json','r'))["color"]
|
||||
|
||||
p=3
|
||||
p1=100
|
||||
d=0.5
|
||||
p2=25
|
||||
p3=25
|
||||
cp=500
|
||||
c=15
|
||||
cmax=8000/0.2
|
||||
cb=200
|
||||
m=0.01
|
||||
r=0.85
|
||||
|
||||
fac1=0.0625
|
||||
fac2=0.1875*0.2
|
||||
fac3=0.4375
|
||||
|
||||
def t(x):
|
||||
return max(0,500-2.2*x)
|
||||
def f1(x):
|
||||
return x*t(x)+x/d*p1+x*(1-r)*p2+x*r*p3
|
||||
def f2(x):
|
||||
return x*c+cp*x/d
|
||||
def f3(x):
|
||||
return x/cb+x/(x+p)+m*x
|
||||
def f(x):
|
||||
return fac1*f1(x)-fac2*f2(x)-fac3*f3(x)
|
||||
|
||||
for x in np.arange(0.2,cb,0.2):
|
||||
if (f2(x)>cmax):
|
||||
cb = x
|
||||
break
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
ranging=np.arange(0.01,cb,0.01)
|
||||
plt.plot(ranging,[f(x) for x in ranging],color=colorList[0],label='f(x)')
|
||||
# plt.plot(ranging,[f1(x) for x in ranging],color=colorList[1],label='f1(x)')
|
||||
# plt.plot(ranging,[f2(x) for x in ranging],color=colorList[2],label='f2(x)')
|
||||
# plt.plot(ranging,[f3(x) for x in ranging],color=colorList[3],label='f3(x)')
|
||||
|
||||
plt.xlabel('x')
|
||||
plt.ylabel('f(x)')
|
||||
plt.legend()
|
||||
plt.savefig('result/optimized1.png')
|
||||
plt.show()
|
||||
48
relation-plot.py
Normal file
48
relation-plot.py
Normal file
@ -0,0 +1,48 @@
|
||||
import json
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
colorList = json.load(open('color/config.json','r'))["color"]
|
||||
|
||||
import csv
|
||||
|
||||
data_pasg = {}
|
||||
data_temp = {}
|
||||
|
||||
with open('data/passenger.csv', 'r') as f:
|
||||
reader = csv.reader(f)
|
||||
header = next(reader)
|
||||
for row in reader:
|
||||
data_pasg[row[0]] = np.array(row[1:],dtype=float)
|
||||
|
||||
with open('data/temperature.csv', 'r') as f:
|
||||
reader = csv.reader(f)
|
||||
header = next(reader)
|
||||
for row in reader:
|
||||
data_temp[row[0]] = np.array(row[1:],dtype=float)
|
||||
|
||||
xList = np.array([])
|
||||
yList = np.array([])
|
||||
for year in range(2014,2024):
|
||||
plt.scatter(data_pasg[str(year)][0], data_temp[str(year)][2], color=colorList[0])
|
||||
xList = np.append(xList,data_pasg[str(year)][0])
|
||||
yList = np.append(yList,data_temp[str(year)][2])
|
||||
|
||||
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])
|
||||
|
||||
plt.xlabel('Passenger')
|
||||
plt.ylabel('SnowFall')
|
||||
plt.title('Relation between Passenger and SnowFall')
|
||||
plt.text( 60000, 110, "k = %f\nb = %f\nR^2 = %f"%(valk,valb,r_squared),color=colorList[1])
|
||||
# plt.show()
|
||||
plt.savefig('result/relation-plot0.png')
|
||||
36
relation-plot2.py
Normal file
36
relation-plot2.py
Normal file
@ -0,0 +1,36 @@
|
||||
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()
|
||||
37
relation-plot3.py
Normal file
37
relation-plot3.py
Normal file
@ -0,0 +1,37 @@
|
||||
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]
|
||||
|
||||
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)')
|
||||
|
||||
|
||||
plt.legend()
|
||||
plt.show()
|
||||
@ -17,7 +17,30 @@ bar_width = 0.25
|
||||
for i in range(1,len(data)):
|
||||
plt.bar(data[0]+(i-2)*bar_width, data[i], label=header[i], color=colorList[i-1], width=bar_width)
|
||||
|
||||
ax2 = plt.twinx()
|
||||
ax2.plot(data[0],data[2]/data[1],label="income/pop",color=colorList[len(data)-1])
|
||||
|
||||
# with open('data/temperature.csv', 'r') as f:
|
||||
# reader = csv.reader(f)
|
||||
# header = next(reader)
|
||||
# data = [row for row in reader]
|
||||
|
||||
plt.legend()
|
||||
|
||||
# data = np.array(data).astype(float).T
|
||||
# ax2 = plt.twinx()
|
||||
# for i in range(1,len(data)):
|
||||
# if i <=2 :
|
||||
# # data[i] = ( data[i] - 32 ) / 1.8
|
||||
# # ax2.plot(data[0], data[i], label=header[i], color=colorList[i-1+len(data)-1])
|
||||
# pass
|
||||
# else:
|
||||
# ax2.plot(data[0], data[i], label=header[i], color=colorList[i-1+len(data)-1])
|
||||
|
||||
# ax2.set_ylabel('Temperature (Celcius)')
|
||||
# # ax2.set_ylim(-10,20)
|
||||
# ax2.legend(loc='upper left')
|
||||
|
||||
plt.xlabel('Year')
|
||||
|
||||
plt.show()
|
||||
27
simplePlot.py
Normal file
27
simplePlot.py
Normal file
@ -0,0 +1,27 @@
|
||||
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(float).T
|
||||
|
||||
bar_width = 0.35
|
||||
|
||||
plt.bar(data[0], data[1], label=header[1], color=colorList[0], width=bar_width)
|
||||
plt.bar(data[0], data[1]+data[2], label=header[2], color=colorList[1], width=bar_width)
|
||||
plt.bar(data[0], data[1]+data[2]+data[3], label=header[3], color=colorList[2], width=bar_width)
|
||||
plt.plot(data[0],data[4], label=header[4], color=colorList[3])
|
||||
plt.plot(data[0],data[5], label=header[5], color=colorList[4])
|
||||
|
||||
plt.legend()
|
||||
plt.xlabel('Year')
|
||||
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user