Scikit-Learn
18
As
per this guiding principle, every specified parameter value is exposed as pubic
attributes.
Steps in using Estimator API
Followings are the steps in using the Scikit-Learn estimator API:
Step 1: Choose a class of model
In this first step, we need to choose a class of model. It can be done by importing the
appropriate Estimator class from Scikit-learn.
Step 2: Choose model hyperparameters
In
this step, we need to choose class model hyperparameters. It can be done by
instantiating the class with desired values.
Step 3: Arranging the data
Next
,
we need to arrange the data into features matrix (X) and target vector(y).
Step 4: Model Fitting
Now,
we need to fit the model to your data. It can be done by calling
fit()
method of the
model instance.
Step 5: Applying the model
After fitting the model, we can apply it to new data.
For supervised learning, use
predict()
method to predict the labels for unknown data. While for unsupervised learning, use
predict()
or
transform()
to infer properties of the data.
Supervised Learning Example
Here, as an example of this process we are taking common case of fitting a line to (x,y)
data i.e.
simple linear regression
.
First, we need to load the dataset, we are using iris dataset:
import
seaborn as sns
iris = sns.load_dataset('iris')
X_iris = iris.drop('species', axis = 1)
X_iris.shape
Output