【发布时间】:2022-10-31 13:22:46
【问题描述】:
我正在使用 Sklearn 在 12 个特征和一个输出上训练多层感知器回归。 StandardScalar() 适合训练数据并应用于所有输入数据。经过一段时间的架构优化训练后,我得到了一个看起来相当准确的模型(<10% 误差)。我现在需要提取权重和偏差,以便在与人交互的系统上实时实现预测。这是通过 my_model.coefs_ 的权重和 my_model.intercepts_ 的偏差来完成的。权重针对我的模型中的节点数量进行了适当的调整,并且偏差对于每一层都有适当的长度。
现在的问题是,我在 MatLab 中实现了矩阵代数,并得到了与 my_model.predict() 产生的完全不同的预测。
我对 2 层 MLP 的重建过程(第一层有 11 个节点,第二层有 10 个节点):
scale() % elementwise subtract feature mean and divide by feature stdev
scaled_obs = scale(raw_obs)
% Up to this point results from MatLab == Sklearn
weight1 = [12x11] % weights to transition from the input layer to the first hidden layer
weight2 = [11x10]
weight3 = [10x1]
bias1 = [11x1] % bias to add to the first layer after weight1 has been applied
bias2 = [10x1]
bias3 = [1x1]
my_prediction = ((( scaled_obs * w1 + b1') * w2 + b2') * w3 + b3);
我也试过
my_prediction2 = ((( scaled_obs * w1 .* b1') * w2 .* b2') * w3 .* b3); % because nothing worked...```
对于我的具体数据:
Sklearn prediction = 1.731
my_prediction = -50.347
my_prediction2 = -3.2075
从 my_model 提取相关参数时,我是否跳过了另一个权重/偏差?我在重建中的操作顺序是否有缺陷?
【问题讨论】:
标签: matlab machine-learning scikit-learn neural-network