赞
踩
每小问都会有对应的代码,并给出部分处理后的数据、可视化图等
已更新好前三问!!
注:目前市面上的资料都已经看过了,小p的那个Python代码,个人认为过分想要出的速度快,实际质量不太好,直接参考很难获奖,全程无脑机器学习,这种代码我可以写一筐。
其他家就基本只是搬运,我6号上午出的第一版思路,里面有两三个错误,依然只会无脑搬运,很离谱。
https://mianbaoduo.com/o/bread/Y5mTlpds
第一问:
import xlrd
import decimal
import pandas as pd
f_name = ‘fujian15.xlsx’
data = xlrd.open_workbook(f_name)
table = data.sheets()[0]
S = [str(table.cell_value(i, 0)) for i in range(1, table.nrows)]
date = [str(table.cell_value(i, 1)) for i in range(1, table.nrows)]
W = [str(table.cell_value(i, 3)) for i in range(1, table.nrows)]
s0 = S[0]
d0 = date[0]
w = 0
w_dir = []
for i in range(len(S)):
s = S[i]
d = date[i]
if s == s0 and d == d0:
w += float(W[i])
else:
w_dir.append({‘s’: str(s0), ‘d’: str(d0), ‘w’: w})
w = 0
s0 = s
d0 = d
第二问:
import xlrd
import numpy as np
from sklearn.ensemble import RandomForestRegressor
import pandas as pd
import warnings
warnings.filterwarnings(‘ignore’)
f_name = ‘q2.xlsx’
data = xlrd.open_workbook(f_name)
table = data.sheets()[0]
df = pd.DataFrame(columns=[‘10cm湿度’, ‘40cm湿度’, ‘100cm湿度’, ‘200cm湿度’]) # 存储最终结果
for mon in [0, 1, 2]: # 1~3月
x1 = [table.cell_value(i, 2) for i in range(mon * 11 + 1, mon * 11 + 12)]
x2 = [table.cell_value(i, 3) for i in range(mon * 11 + 1, mon * 11 + 12)]
X = np.array([x1, x2]).transpose()
y1 = np.array([table.cell_value(i, 4) for i in range(mon * 11 + 1, mon * 11 + 12)]).flatten()
y2 = np.array([table.cell_value(i, 5) for i in range(mon * 11 + 1, mon * 11 + 12)]).flatten()
y3 = np.array([table.cell_value(i, 6) for i in range(mon * 11 + 1, mon * 11 + 12)]).flatten()
y4 = np.array([table.cell_value(i, 7) for i in range(mon * 11 + 1, mon * 11 + 12)]).flatten()
t = np.array(range(len(x1))).reshape(-1, 1)
t_test = np.array(range(12)).reshape(-1, 1)
regressor1 = RandomForestRegressor()
regressor1.fit(t, x1) # 蒸发量与时间关系模型
regressor2 = RandomForestRegressor()
regressor2.fit(t, x2) # 降水量与时间关系模型
regressor3 = RandomForestRegressor()
regressor3.fit(X, y1) # 10cm湿度预测模型
regressor4 = RandomForestRegressor()
regressor4.fit(X, y2) # 40cm湿度预测模型
regressor5 = RandomForestRegressor()
regressor5.fit(X, y3) # 100cm湿度预测模型
regressor6 = RandomForestRegressor()
regressor6.fit(X, y4) # 200cm湿度预测模型
第三问:
import xlrd
import numpy as np
from sklearn.ensemble import RandomForestRegressor
import pandas as pd
import warnings
warnings.filterwarnings(‘ignore’)
f_name = ‘q3.xlsx’
data = xlrd.open_workbook(f_name)
table = data.sheets()[0]
df = pd.DataFrame(columns=[‘plot’, ‘SOC’, ‘SIC’, ‘STC’, ‘N’, ‘C/N’]) # 存储最终结果
plots = np.array([table.cell_value(i, 1) for i in range(1, table.nrows)]).flatten()
plot = []
[plot.append(i) for i in plots if i not in plot]
for y in range(12): # 12个分区
t = np.array(range(11)).reshape(-1, 1)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。