How to make inverse_transform over a different df shape than the one where the fit was applied?

78 Views Asked by At

I have the next DF and I use standardscaler.

#datos
               LIBRANZA IPC IBR
FECHA           
2020-10-09  2.000   5.620   1.741
2020-10-10  0.000   5.620   1.741
2020-10-11  0.000   5.620   1.741
2020-10-12  0.000   5.620   1.741
2020-10-13  1.000   5.620   1.744

I have like result the next DF.

#datos_estandarizados
           LIBRANZA IPC IBR
FECHA           
2020-10-09  -1.281  -0.393  -0.871
2020-10-10  -1.298  -0.393  -0.871
2020-10-11  -1.298  -0.393  -0.871
2020-10-12  -1.298  -0.393  -0.871
2020-10-13  -1.290  -0.393  -0.871

With the last DF I'm running different ML models to get a forecast over the variable LIBRANZA which is the objective, but I have a problem when I'm trying to get inverse_transform over the forecast because the fit was made over a different shape of the DF I think, but not sure. I'm getting the next error, but I don't know how to solve it.

ValueError: non-broadcastable output operand with shape (932,1) doesn't match the 
broadcast shape (932,3)

Some who can help me to solve it pls.

These is the Code to fit

from sklearn.preprocessing import StandardScaler

encabezados = datos.columns
index = datos.index

scaler = StandardScaler()

X_estandarizado = scaler.fit_transform(datos)

datos_estandarizados = pd.DataFrame(X_estandarizado, index=index, columns=encabezados)

#Completa los huecos en la serie con NULL
datos_estandarizados = datos_estandarizados.asfreq('D') 

datos_estandarizados.head()

and this is the code to inverse_transform

prediccion_libranza = predicciones2.reset_index(drop=False)

prediccion_libranza.columns = ["FECHA", "PREDICCIÓN"]

prediccion_libranza = prediccion_libranza.set_index('FECHA')

X_desestandarizado = scaler.inverse_transform(prediccion_libranza)
0

There are 0 best solutions below