0
$\begingroup$

According to the documentation of fit(self, X[, y]) method of sklearn.preprocessing.Normalizer(), it does nothing and return the estimator unchanged. I understand that if I intend to normalize data I can simply pass the data to the Normalizer() function. so what is the use of use of fit method. Moreover, normalization is not a learning algorithm so why is there a fit() method?

$\endgroup$
3
$\begingroup$

In scikit-learn, many preprocessing operations follow the Estimator API (i.e. having fit and transform methods). The benefit of conforming to the Estimator API is that the object can be included in a data transformation pipeline. Some of the benefits of pipelines are described in the docs:

Pipeline can be used to chain multiple estimators into one. This is useful as there is often a fixed sequence of steps in processing the data, for example feature selection, normalization and classification. Pipeline serves multiple purposes here:

Convenience and encapsulation: You only have to call fit and predict once on your data to fit a whole sequence of estimators.

Joint parameter selection: You can grid search over parameters of all estimators in the pipeline at once.

Safety: Pipelines help avoid leaking statistics from your test data into the trained model in cross-validation, by ensuring that the same samples are used to train the transformers and predictors.

Because the Normalizer estimator is stateless, its fit method is a no-op. But if it was missing the fit method, then it could not be used in scikit-learn Pipelines.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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