Keras:将Predict与经过规范化数据训练的模型一起使用吗? [英] Keras: Using Predict with a Model Trained with Normalized Data?

查看:242
本文介绍了Keras:将Predict与经过规范化数据训练的模型一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Keras中创建一个深层神经网络,以使用表格数据执行NN回归.最佳实践是对输入和输出序列进行归一化.我还想使用predict函数为各种输入集提供模型输出的估计.如果对训练数据进行了归一化,那么我想我还需要使用相同的缩放参数来归一化predict数据集.最好的方法是什么?有没有一种方法可以自动规范化模型中的数据?

I'm creating a deep neural network in Keras to perform an NN regression using tabular data. Best practice is to normalize the inputs and output series. I'd also like to use the predict function to provide estimates of the model's output for various sets of inputs. If the training data was normalized, I assume I'll need to also normalize the predict data set using the same scaling parameters. What's the best way to do this? Is there a way to automatically normalize the data within the model?

推荐答案

我通常喜欢使用sklearn,它确实保存了参数,并允许您反变换"回原始值.对于预测,您可以通过inverse_transform函数将其发送以获取其真实的预测值.

I typically like to use sklearn for this, and it does save the parameters and allows you to "inverse transform" back to the original values. For predictions you would send them through the inverse_transform function to get their real predicted values.

这里是一个工作示例,供您参考.洁牙机的参数可以轻松调整.

Here is a working example for you to reference. The parameters of the scalers can be easily adjusted.

from sklearn.preprocessing import MinMaxScaler, StandardScaler
import numpy as np

example = np.array([0., 1., 1., 0., 2., 3., 4., 4., 5.]).reshape(-1, 1)

# MinMax Scaling Example
scaler = MinMaxScaler(feature_range=(0.01, 0.99))
min_max_scaled = scaler.fit_transform(example)
min_max_orig = scaler.inverse_transform(min_max_scaled)

# Normalizing Example  (mean 0, std 1)
norm = StandardScaler()
normalized = norm.fit_transform(example)
normalized_orig = norm.inverse_transform(normalized)

这篇关于Keras:将Predict与经过规范化数据训练的模型一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆