transform Vs. 'it_transform in sklearn Python

Last Updated : 28 Sep, 2026

In scikit-learn, fit(), transform(), and fit_transform() are commonly used while preprocessing data. It uses transformers for operations such as scaling, encoding, imputing, feature selection, and dimensionality reduction.

  • fit() learns parameter from the given data.
  • transform() uses those learned parameters to modify data.
  • fit_transform() learns the parameters and transforms the same data in one operation.

fit() method

This method learns the parameters required by a transformer from the input data. It does not perform the final transformation of the input values.

Example:

Python
from sklearn.preprocessing import StandardScaler

data = [[1, 10],
        [2, 20],
        [3, 30]]

scaler = StandardScaler()

scaler.fit(data)

print(scaler.mean_)

Output:

[ 2. 20.]

Explanation:

  • fit() calculates the required statistics from the given data.
  • StandardScaler stores the calculated mean and standard deviation.
  • Original values are not transformed during this step.
  • fit() returns the fitted estimator itself.

transform() Method

It applies the transformation using parameters that were learned during fit().

Example:

Python
from sklearn.preprocessing import StandardScaler

data = [[1, 10],
        [2, 20],
        [3, 30]]

scaler = StandardScaler()

scaler.fit(data)

transformed_data = scaler.transform(data)

print(transformed_data)

Output:

Screenshot_2026-09-25_14-47-00
Output

Explanation:

  • fit() first learns the statistics from data.
  • transform() then uses those statistics to produce the scaled values.

fit_transform() Method

This method combines fitting and transformation into one operation. Learns the required parameters from the supplied data and immediately transforms that same data.

Example:

Python
from sklearn.preprocessing import StandardScaler

data = [[1, 10],
        [2, 20],
        [3, 30]]

scaler = StandardScaler()

transformed_data = scaler.fit_transform(data)

print(transformed_data)

Output:

Screenshot_2026-09-25_14-56-13
Output

Explanation:

  • fit_transform(), learns from the data and applies standard scaling Normalization in the data itself.
  • Same input data is used for learning and transformation.

Key Comparison

MethodLearns ParametersTransforms DataReturns
fit()YesNoFitted estimator
transform()NoYesTransformed data
fit_transform()YesYesTransformed data
Comment