fit_transform和inverse_transform在两个不同的脚本上

发布于 2025-02-11 16:35:30 字数 588 浏览 2 评论 0原文

如何fit_transform& inverse_transform在单独的脚本中?

我首先在脚本中标准化数值目标(整数)。
然后,我使用其他脚本实时预测这些数值目标(回归)。

fit_transform& inverse_transform函数def在第三个脚本中。

scaler = MinMaxScaler(copy=True, feature_range=(0.,1.))

def normalize(array):
    array = scaler.fit_transform(array).flatten()
    return array

def inverse_norm(array):
    array = scaler.inverse_transform(array).flatten()
    return array

天真,我只是“ inverse_transform”我的实时脚本中的预测值。
但是预测的值不在原始数值目标中:这些是浮点数很小的。

感谢您的帮助。

How to fit_transform & inverse_transform in separate scripts?

I first normalize numerical targets (integers) in a script.
Then, I use an other script to predict in real-time these numerical targets (regression).

fit_transform & inverse_transform functions def are in a third script.

scaler = MinMaxScaler(copy=True, feature_range=(0.,1.))

def normalize(array):
    array = scaler.fit_transform(array).flatten()
    return array

def inverse_norm(array):
    array = scaler.inverse_transform(array).flatten()
    return array

Naively, I just "inverse_transformed" the predicted values within my real-time script.
But predicted values were not in the range as the original numerical targets: these are little float numbers.

Thank you for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疏忽 2025-02-18 16:35:30

总的来说,我认为您不想将目标变量归一化,但是如果您想这样做,则可以使用标签编码器而不是Minmax Scaleer,该标签量表可用于正常化功能

In general I think you don't want to normalize you target variable but if you want to do so you can use a label encoder instead of a minmax scaler which is rather use to normalize features

沉溺在你眼里的海 2025-02-18 16:35:30

由于Mattornothing,我解决了自己的问题。
只需写下答案即可。

第一个脚本:

myNormalizedArray = (myArray - myArrayMin) / (myArrayMax - myArrayMin)

第二个脚本:

myDenormalizedArray = myPredicedArray * (myArrayMax - myArrayMin) + myArrayMin

其中myArray& myPredicedArray是numpy数组。

I fixed myself the problem thanks to mattOrNothing.
Just write down the answer.

First script:

myNormalizedArray = (myArray - myArrayMin) / (myArrayMax - myArrayMin)

Second script:

myDenormalizedArray = myPredicedArray * (myArrayMax - myArrayMin) + myArrayMin

Where myArray & myPredicedArray are numpy arrays.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文