1

我正在嘗試使用MLPRegressor來適合預定義的3D功能。問題是,我無法打印正確的結果,因此繪製時我的配件看起來很糟糕。Python:適合使用MLPRegressor的3D功能

功能了下列文件:

def threeDFunc(xin,yin): 
    z = np.zeros((40,40)) 
    for xIndex in range(0,40,1): 
     for yIndex in range(0,40,1): 
      z[xIndex,yIndex]=(np.exp(-(xin[xIndex]**2+yin[yIndex]**2)/0.1)) 
    return z 



xThD = np.arange(-1,1,0.05) 
yThD = np.arange(-1,1,0.05) 
zThD = threeDFunc(xThD, yThD) 

3Dplot

以上情節是什麼,應該接近。

3Dplot with approximation

紅色是它做什麼。

的代碼看起來是這樣的:

classifier = neural_network.MLPRegressor(hidden_layer_sizes=(200, 200), activation='logistic', learning_rate='adaptive') 

xy = np.array((xThD.flatten(),yThD.flatten())) 

classifier.fit(np.transpose(xy), zThD) 

pre = classifier.predict(np.transpose(xy)) 

import pylab 
from mpl_toolkits.mplot3d import Axes3D 

fig = pylab.figure() 
ax = Axes3D(fig) 
X, Y = np.meshgrid(xThD, yThD) 
ax.plot_wireframe(X, Y, zThD) 
ax.plot_wireframe(X, Y, pre, color='red') 
print(np.shape(zThD)) 
print(np.shape(pre)) 
plt.show() 

回答

0

改變激活功能的雙曲正切函數與activation='tanh'和求解器lbfgs與solver='lbfgs'

如果你的分類實例,然後如下所示,紅色和藍色的曲線應該是幾乎相同:

classifier = neural_network.MLPRegressor(hidden_layer_sizes=(200, 200), solver='lbfgs', activation='tanh', learning_rate='adaptive')