Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you treat a new sample after training a model using sklearn preprocessing scale?

Tags:

scikit-learn

Assume I have a dataset X and labels Y for a supervised machine learning task.

Assume X has 10 features and 1,000 samples and I believe that it is appropriate to scale my data using sklearn.preprocessing.scale. This operation is taken and I train my model.

I now wish to use it for model for new data, so I collect a new sample of the 10 features of X and wish to use my trained model to classify this sample.

Is there an easy way to apply the same scaling that was performed on X before training my model to this single new sample, before attempting classification?

If not, is the only solution to have retained a copy of X before scaling and to add my new sample to this data and then scale this dataset and attempt classification on the new sample after it has been scaled via this process?

like image 263
Kieran Avatar asked Dec 18 '25 14:12

Kieran


1 Answers

use class api instead of function api. like preprocessing.MinMaxScaler, preprocessing.StandardScaler

http://scikit-learn.org/stable/modules/preprocessing.html#preprocessing

The function scale provides a quick and easy way to perform this operation on a single array-like dataset

The preprocessing module further provides a utility class StandardScaler that implements the Transformer API to compute the mean and standard deviation on a training set so as to be able to later reapply the same transformation on the testing set.

like image 170
BugKiller Avatar answered Dec 20 '25 02:12

BugKiller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!