i have calculated two scalers as : Suppose mean_ and var_ have been obtained as above…
- User
i have calculated two scalers as :
Suppose mean_ and var_ have been obtained as above
x_scaler = StandardScaler() x_scaler.mean_ = f_mean_ x_scaler.var_ = f_var_ x_scaler.scale_ = np.sqrt(f_var_)
y_scaler = StandardScaler() y_scaler.mean_ = t_mean_ y_scaler.var_ = t_var_ y_scaler.scale_ = np.sqrt(t_var_)
how can i save them?
- Assistant
To save the
StandardScalermodels (x_scalerandy_scalerin your case) you've manually fitted, you can use thejoblibmodule, which is a part of the standard SciPy ecosystem and is designed for efficiently saving and loading Python objects. Here's how you can do it:from sklearn.preprocessing import StandardScaler import numpy as np import joblib # Make sure you have joblib installed # Assuming f_mean_, f_var_, t_mean_, and t_var_ are defined elsewhere in your code. x_scaler = StandardScaler() x_scaler.mean_ = np.array(f_mean_) # Ensure these are numpy arrays x_scaler.var_ = np.array(f_var_) x_scaler.scale_ = np.sqrt(f_var_) y_scaler = StandardScaler() y_scaler.mean_ = np.array(t_mean_) y_scaler.var_ = np.array(t_var_) y_scaler.scale_ = np.sqrt(t_var_) # Save the scalers to disk joblib.dump(x_scaler, 'x_scaler.sav') joblib.dump(y_scaler, 'y_scaler.sav')Make sure to replace
'x_scaler.sav'and'y_scaler.sav'with the path and filename you prefer for saving the scaler objects.