#预测因子(海温) #nino3.4赤道东太平洋(190-220,-5-5) a22=sst_djf.sel(lon=slice(190,220),lat=slice(5,-5)).mean(axis=1).mean(axis=1) a2=(a22-a22.mean())/a22.std() #赤道印度洋(50-80,-5-5) a33=sst_djf.sel(lon=slice(50,100),lat=slice(5,-5)).mean(axis=1).mean(axis=1) a3=(a33-a33.mean())/a33.std() #预测因子(环流场) #南欧(30-40,35-45) b11=hgt_djf.sel(lon=slice(30,40),lat=slice(45,35)).mean(axis=1).mean(axis=1) b1=(b11-b11.mean())/b11.std() #太平洋副高(120-180,-10-10) b22=hgt_djf.sel(lon=slice(120,180),lat=slice(10,-10)).mean(axis=1).mean(axis=1) b2=(b22-b22.mean())/b22.std() #印度洋(60-80,-10-10) b33=hgt_djf.sel(lon=slice(60,80),lat=slice(10,-10)).mean(axis=1).mean(axis=1) b3=(b33-b33.mean())/b33.std() x=np.vstack([(a2,a3,b1,b2,b3)]).T x2=np.vstack([(a2,b1)]).T y=pre_standard #多元线性回归 res=np.linalg.lstsq(x,y,rcond=None) n=res[0] ##各项系数 y_fit=(n.T*x).sum(axis=1) #拟合数据 res2=np.linalg.lstsq(x2,y,rcond=None) n2=res2[0] ##各项系数 y_fit2=(n2.T*x2).sum(axis=1) #拟合数据 #可视化 time=np.arange(1961,2017,1) fig = plt.figure(figsize=[16, 5]) ax = fig.add_subplot() ax.plot(time, y,marker='o', color='gray', markersize=5) ax.plot(time, y_fit,marker='*', color='b', markersize=5) ax.plot(time, y_fit2,marker='^', color='r', markersize=5) ax.set_title('model',fontsize=20,fontweight='bold') ax.set_xlabel('Time') ax.set_ylabel('Pre') plt.legend(['Source data','Fitted1','Fitted2'],frameon=False,loc='best') plt.show()选做剔除一年的交叉检验,独立试报