根据这里的答案Implementation of Gaussian Process Regression in Python y(n_samples, n_targets)
不是重复的问题。它基于这些答案,我有不同的问题
我想从.txt文件中读取我的样本,其中包含每个点(6x3)的3D坐标,如下所示:
30.1678, -173.569, 725.724
-44.6401, -182.179, 733.301
39.7365, -187.244, 792.871
-9.43636, -200.9, 794.027
-38.2015, -199.272, 816.198
-17.6029, -189.19, 855.988
我的3D(1x3)目标点之一:
14.8016, -175.911, 779.752
如果我尝试按如下方式阅读我的文件并进行预测:
xFile= io.BytesIO(open('1_xRSImageCoordinates.txt', 'rb').read().replace(b'\n', b','))
xData= np.genfromtxt(xFile, dtype= float, delimiter= ',')
print("xData= ", xData)
yFile= io.BytesIO(open('1_y1InCoordinates.txt', 'rb').read().replace(b'\n', b','))
yData= np.genfromtxt(yFile, dtype= float, delimiter= ',')
print("yData= ", yData)
gaus = GP(xData, yData, kernel, R= R)
x_guess = np.linspace(-10, 10, 400)
y_pred = np.vectorize(gaus.predict)(x_guess)
colors = ['b', 'c', 'y', 'm', 'r']
plt.scatter(xData, yData, marker='o', label=u'Observations', color= colors[1])
plt.plot(x_guess, y_pred[0], c="b" , label=u'Prediction')
plt.plot(x_guess, y_pred[0] - np.sqrt(y_pred[1]) * 3, "r:" , label=u'Confidence Interval -')
plt.plot(x_guess, y_pred[0] + np.sqrt(y_pred[1]) * 3, "r:" , label=u'Confidence Interval +')
然后我得到
xData= [ 30.1678 -173.569 725.724 -44.6401 -182.179 733.301
39.7365 -187.244 792.871 -9.43636 -200.9 794.027 -38.2015 -199.272 816.198 -17.6029 -189.19 855.988 nan]
yData= [ 14.8016 -175.911 779.752 nan]
File "C:/Users/trm/workspace/gaussianProcess/gaussianProcess.py", line 72, in predict
m_expt = (sigma_1_2.T * np.mat(self.sigma).I) * np.mat(self.y).T
File "C:\Users\trm\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\matrixlib\defmatrix.py", line 309, in __mul__
return N.dot(self, asmatrix(other))
ValueError: shapes (1,19) and (4,1) not aligned: 19 (dim 1) != 4 (dim 0)
我不明白为什么纳米变量包含在数组中。我猜我正确地解析了文件。或不?为什么我最后得到那些价值错误?
感谢您的帮助