How do I know whether a sklearn scaler is already fitted or not?

Solution 1:

According to you example, in order to determine if your object is a Fitted scaler, one checks if the attribute n_features_in_ exists in the object of interest.

from sklearn.preprocessing import StandardScaler

data = [[0, 0], [0, 0], [1, 1], [1, 1]]
scaler = StandardScaler()
scaler_fit = StandardScaler().fit(data)

def is_fit_called(obj):
    return hasattr(obj, "n_features_in_")

print(is_fit_called(scaler)) #False
print(is_fit_called(scaler_fit)) #True