在 0 和 1 之间标准化忽略 NaN [英] Normalise between 0 and 1 ignoring NaN

查看:16
本文介绍了在 0 和 1 之间标准化忽略 NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于从 xy 的可能包含 NaN 的数字列表,我如何在 0 和 1 之间标准化,忽略NaN 值(它们保持为 NaN).

通常我会使用 MinMaxScaler (

<小时>

选项 1
最小最大缩放

new = s.sub(s.min()).div((s.max() - s.min()))新的历史()

<小时>

不符合要求
我把这些放进去是因为我想

选项 2
sigmoid

sigmoid = lambda x: 1/(1 + np.exp(-x))新 = sigmoid(s.sub(s.mean()))新的历史()

<小时>

选项 3
tanh(双曲正切)

new = np.tanh(s.sub(s.mean())).add(1).div(2)新的历史()

For a list of numbers ranging from x to y that may contain NaN, how can I normalise between 0 and 1, ignoring the NaN values (they stay as NaN).

Typically I would use MinMaxScaler (ref page) from sklearn.preprocessing, but this cannot handle NaN and recommends imputing the values based on mean or median etc. it doesn't offer the option to ignore all the NaN values.

解决方案

consider pd.Series s

s = pd.Series(np.random.choice([3, 4, 5, 6, np.nan], 100))
s.hist()


Option 1
Min Max Scaling

new = s.sub(s.min()).div((s.max() - s.min()))
new.hist()


NOT WHAT OP ASKED FOR
I put these in because I wanted to

Option 2
sigmoid

sigmoid = lambda x: 1 / (1 + np.exp(-x))

new = sigmoid(s.sub(s.mean()))
new.hist()


Option 3
tanh (hyperbolic tangent)

new = np.tanh(s.sub(s.mean())).add(1).div(2)
new.hist()

这篇关于在 0 和 1 之间标准化忽略 NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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