If you didn't save your scaler instance (the StandardScaler in this case) alongside your model, you have a few options depending on your situation:
1. Re-train and Save the Scaler
If you have access to the original training data (or at least representative training data with the same distribution), the best approach is to re-scale your data using a new StandardScaler instance, train your model again if needed, and then save both the model and the scaler this time. This ensures that any future data can be properly scaled using the exact same scaling parameters.
Retrain and save both model and scaler:
Assuming you're starting with original training data, here's how you can proceed:
from sklearn.preprocessing import StandardScaler
from sklearn.externals import joblib # For older scikit-learn versions
# For newer versions: from joblib import dump
# Assume X_train is your training data
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
# Train your model here (assuming `model` is your machine learning model)
# model.fit(X_train_scaled, y_train)
# After training, save both the scaler and the model
joblib.dump(scaler, 'your_scaler.joblib')
joblib.dump(model, 'your_model.joblib')
2. Manually Reconstruct the Scaler
If re-training the model is not an option for you (e.g., due to loss of original training data or computational constraints) and you absolutely must use the same model, a less ideal option is to try and manually reconstruct the scaler parameters if you know them or can estimate them. This is not recommended unless you have no other options, as it can lead to inconsistencies and inaccuracies in scaling.
3. Use the Model Without Re-scaling (Not Recommended)
Using the model without properly scaling new input data as you did with your training data is also an option, but it's highly likely to lead to subpar model performance, especially if your model significantly relies on feature scaling (e.g., SVMs, neural networks, etc.). This method is generally not recommended unless your data is already in a similar scale or the features have negligible scale differences — which is rarely the case.
Recommendation:
The recommended approach is to try and regenerate your preprocessing pipeline as accurately as possible with the original or similar data, and ensure both the model and scaler are saved for future use. Unfortunately, without the original scaler, using the trained model on new data that isn't scaled similarly to your training data will likely result in inaccurate predictions.