Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 438
hyon Avatar asked Jun 14 '17 18:06

hyon


People also ask

How does StandardScaler work in Sklearn?

StandardScaler standardizes a feature by subtracting the mean and then scaling to unit variance. Unit variance means dividing all the values by the standard deviation.

What does the function StandardScaler () from Sklearn preprocessing do?

sklearn. preprocessing . StandardScaler. Standardize features by removing the mean and scaling to unit variance.

Does Standard scaler normalize?

StandardScaler() will normalize the features i.e. each column of X, INDIVIDUALLY, so that each column/feature/variable will have μ = 0 and σ = 1 .


Video Answer


2 Answers

Yeah, and it's conveniently called inverse_transform.

The documentation provides examples of its use.

like image 167
Arya McCarthy Avatar answered Dec 15 '22 14:12

Arya McCarthy


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) 
like image 37
rohan chikorde Avatar answered Dec 15 '22 16:12

rohan chikorde