Skip to content
← All questions

How do I apply min-max normalization in scikit-learn?

Import `MinMaxScaler` from `sklearn.preprocessing`, instantiate it, and call `fit_transform` on the selected DataFrame columns. This fits the scaler to the data (learning min/max) and transforms the values to the [0, 1] range.

Conditions

  • Input data is numerical.
  • Scikit-learn library is installed.

Reasoning, step by step

  1. Import the class: `from sklearn.preprocessing import MinMaxScaler`.
  2. Create an instance: `scaling = MinMaxScaler()`.
  3. Apply to selected columns: `scaled_data = scaling.fit_transform(df[['Alcohol', 'Malic']])`.

Example

The video demonstrates: `from sklearn.preprocessing import MinMaxScaler`, `scaling=MinMaxScaler()`, and `scaling.fit_transform(df[['Alcohol', 'Malic']])`, resulting in values between 0 and 1.

Common misconceptions

  • Forgetting to select only numerical columns, causing errors with categorical data.
  • Using `transform` without `fit` on new data without ensuring the scaler was already fitted on training data.

Watch the explanation

Connected concepts

Explore next

Related questions

Understand why

↗
Understand why

↗
Meet the concept

↗
Meet the concept

↗

Answers are generated from source material and independently checked. Consult the original video or creator if something is unclear.