0
$\begingroup$

I am learning ML and facing confusion about data scaling. For example, I have the following data:

Weight(KG) Balance($)
75 3401542
99 4214514

Now, if I use StandardScaler, I may get something like this:

Weight(KG) Balance($)
-0.23214788 -0.73214788
-0.25214788 -0.83214788

Now, I can train_test_split data, then train the model and find the accuracy of the model. Suppose, the accuracy is 82%. Now, if I want to test the model from user data by model.predict(), then user will not put scaled input, because users are not aware of the internal process of the model, they will put real-life values, like weight= 102 and balance= 1025455. Now, since my model is trained and tested with scaled data, how it will handle real-life values in real-life applications without scaling?

$\endgroup$

2 Answers 2

1
$\begingroup$

You need to introduce a scaling step between receiving the user input and feeding it to the model.

Normally, models are not directly accessible to users. Instead, there is usually a piece of software that manages the model, loading it, preparing its input, and handling its output.

$\endgroup$
1
$\begingroup$

Scaling procedure will stay a part of your model even after development: you can look at it this way, you are LEARNING standard deviations and means of features in your dataset while creating a model (although, if the scaling/normalization is not a part of batch normalization, deviation and mean are non-trainable parameters, something you calculate once and use) and you will use the standard deviation and mean of the features from your training data on your test data / real-life values you receive before you feed them into the model to make predictions.

Keep a lookout on one rather big mistake beginners make: parameters for standardization need to be learned on your training test only. So don't standardize your data before train-test split, but after. The pipeline should go like this

  1. Split the data into train and test
  2. Learn the scaling parameters on the train data only
  3. scale the test data with the scaling parameters you learned on the train data
  4. If you are using eval sets for early stopping, the 3. applies on them as well, given they are similar in nature to the test data. If you are using cross validation, same applies.

This way, you will get a better notion on how your data behaves in the real world. This applies for min-max scaling and standard scaling alike. Keep in mind tree-based algorithms don't benefit from scaling.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.