Estimator API offers a uniform interface for various ML applications, ensuring all Scikit-Learn algorithms utilize it. An estimator learns from data, applicable for classification, regression, clustering, or as a transformer to extract features from raw data. All estimator objects have a fit method for data (obtained from the dataset) fitting as below.
estimator.fit(data)
Next, all estimator parameters can be configured upon instantiation through specific attributes, as follows, where the output of the code is 1 .
estimator = Estimator(param1 = 1, param2 = 2)
estimator.param1
Estimated parameters from fitted data become attributes of the estimator object, marked by an underscore at the end, as below.
estimator.estimated_param_
The main steps for using an estimator API are as follows:
- Estimation and decoding of a model: The estimator object estimates and decodes a model as a deterministic function, as object construction parameters, global random state (numpy.random) when random_state is none, and data from the latest fit(), fit_transform(), or fit_predict() calls, plus data from partial_fit() calls.
- Mapping non-rectangular data representation into rectangular data: It transforms input samples into array-like feature objects of variable lengths for each individual sample.
- Distinction between core and outlying samples: It models the distinction between core and outlying samples using the fit(), fit_predict() if transductive, and predict() if inductive methods.
The five steps in applying Scikit-Learn estimator API are as follows:
- Step 1: Selecting a class of model by importing a suitable Estimator class from Scikit-Learn.
- Step 2: Selecting model hyperparameters by instantiating the class with the desired values.
- Step 3: Arranging the data into the features matrix (X; denoted by data in the examples) and the target vector(y; denoted by target in the examples).
- Step 4: Model fitting to the data by calling the fit() method of the model instance.
- Step 5: Applying the model to new data, where supervised learning uses predict() for predicting the labels for unknown data, and unsupervised learning uses predict() or transform() for inferring properties from the data.
The following example uses the steps mentioned above from the estimator API for supervised learning using linear regression based on a random dataset.
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
rnd = np.random.RandomState(35)
data = 10*rnd.rand(40)
target = 2*data-1+rnd.randn(40)
plt.scatter(data, target)
plt.savefig("supervised_learning_training_set_plot.png")
model = LinearRegression(fit_intercept = True)
Data = data[:, np.newaxis]
print(Data.shape, "\n")
model.fit(Data, target)
print(model.coef_)
print(model.intercept_)
data_fit = np.linspace(-1, 11)
Data_fit = data_fit[:, np.newaxis]
target_fit = model.predict(Data_fit)
plt.scatter(data, target)
plt.plot(data_fit, target_fit)
plt.savefig("supervised_learning_predict_plot.png")
Output
(40, 1)
[1.99839352]
-0.989545945777504


The example below involves reducing the iris dataset’s dimensionality for better visualization using principal component analysis (PCA), a quick linear technique for dimensionality reduction.
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
iris = sns.load_dataset('iris')
data_iris = iris.drop('species', axis = 1)
print(data_iris.shape)
target_iris = iris['species']
print(target_iris.shape)
rnd = np.random.RandomState(35)
data = 10*rnd.rand(40)
target = 2*data-1+rnd.randn(40)
plt.scatter(data, target)
plt.savefig("unsupervised_learning_training_set_plot.png")
model = PCA(n_components=2)
model.fit(data_iris)
data_2D = model.transform(data_iris)
iris['PCA1'] = data_2D[:, 0]
iris['PCA2'] = data_2D[:, 1]
sns.lmplot(x="PCA1", y="PCA2", hue='species', data=iris, fit_reg=False).savefig("unsupervised_learning_transform_plot.png")
Output
(150, 4)
(150,)


References
- Hackeling, G. (2017). Mastering Machine Learning with scikit-learn, 2nd Edition. Packt Publishing Ltd.
- Géron, A. (2019). Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow, 2nd Edition. O’Reilly Media, Inc.
- Tutorials Point. Scikit Learn Tutorial. Retrieved November 20, 2025, from https://www.tutorialspoint.com/.

Leave a Reply