[sklearn][standardscaler] can I inverse the standardscaler for the model output?

雨燕双飞 提交于 2019-12-10 12:37:52

问题


I have some data structured as below, trying to predict t from the features.

train_df

t: time to predict
f1: feature1
f2: feature2 
f3:......

Can t be scaled with StandardScaler, so I instead predict t' and then inverse the StandardScaler to get back the real time?

For example:

from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(train_df['t'])
train_df['t']= scaler.transform(train_df['t'])

run regression model,

check score,

!! check predicted t' with real time value(inverse StandardScaler) <- possible?


回答1:


Yeah, and it's conveniently called inverse_transform.

The documentation provides examples of its use.




回答2:


Here is sample code. You can replace here data with train_df['colunm_name']. Hope it helps.

from sklearn.preprocessing import StandardScaler
data = [[1,1], [2,3], [3,2], [1,1]]
scaler = StandardScaler()
scaler.fit(data)
scaled = scaler.transform(data)
print(scaled)

# for inverse transformation
inversed = scaler.inverse_transform(scaled)
print(inversed)


来源:https://stackoverflow.com/questions/44552031/sklearnstandardscaler-can-i-inverse-the-standardscaler-for-the-model-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!