简体   繁体   English

神经网络的非线性回归

[英]Non-linear regression with neural networks

How do you create an NN to solve for example: 2 * x ** 3 + 4 * x + 8 + random noise?你如何创建一个神经网络来解决例如:2 * x ** 3 + 4 * x + 8 + 随机噪声? I can do this easily with LinearRegression from sklearn, but I'd like to be able to achieve this for a multivariate sample where I have no idea wether the function is log/exp/poly/etc.我可以使用 sklearn 的 LinearRegression 轻松做到这一点,但我希望能够在我不知道 function 是否为 log/exp/poly/etc 的多元样本中实现这一点。 Thank you!谢谢! Ashkan阿什坎

The nonlinearity in Neural Network can be achieved by simply having a layer with a nonlinear activation function, eg (relu).神经网络中的非线性可以通过简单地使用具有非线性激活 function 的层来实现,例如(relu)。 For example:例如:

from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense

model = Sequential()
model.add(Dense(10, activation='relu', kernel_initializer='he_normal', input_shape=(n_features,)))
model.add(Dense(1))

model.compile(optimizer='adam', loss='mse')
model.fit(X_train, y_train, epochs=10, batch_size=16, verbose=0)

Just needed 3 more layers of these - thanks Tony!只需要再增加 3 层——谢谢托尼!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM