I would like to understand how to apply inverse transformation in a pipeline, and not using the StandardScaler function directly.
The code that I am using is the following:
import pandas as pd
import numpy as np
from sklearn.cluster import KMeans
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder, StandardScaler
categoric = X.select_dtypes(['object']).columns
numeric = X.select_dtypes(['int']).columns
tf = ColumnTransformer([('onehot', OneHotEncoder(), categoric),
('scaler', StandardScaler(), numeric)])
X_preprocessed = tf.fit_transform(X)
model = KMeans(n_clusters=2, random_state=24)
model.fit(X_preprocessed)
After getting the output of a given model (KMeans in this case), how can I get back the original scale of the numeric values of any X dataframe?
I know StandardScaler has a method (.inverse_transformation) to do that, but my question arises in the use of a pipeline with ColumnTransformer.
P.S.: The objective of doing so is to interpret the centroids of the model.