0% found this document useful (0 votes)
25 views8 pages

Scikit Learn

Scikit - Learn

Uploaded by

ryanhazo47
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views8 pages

Scikit Learn

Scikit - Learn

Uploaded by

ryanhazo47
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Training a Perceptron via Scikit-

Learn

Nicodemus M. M.
Scikit-Learn

• Scikit-learn is a powerful, open-source Python library for machine learning and data analysis.
• It provides simple and e cient tools for various data mining and machine learning tasks, making it an
essential tool for both beginners and experienced data scientists.
ffi
Let Go!
• We are going to use only two features
from the Iris ower dataset for
visualization purpose.

• Iris dataset already exists on sklearn and


once imported, it can be accessed by
just calling iris.data

• We have extracted petal length and petal


width of the 150 ower samples to the
feature Matrix X and the corresponding
class labels of the ower species to the
vector y:
fl
fl
fl
70, 30 Training and Test Set

• Without xing the random_state, the split


will be di erent each time you run the code.

• By setting random_state to a speci c integer


(e.g., 42 or 0), you ensure that the data is
split the same way every time you run the
code.
fi
ff
fi
Scaling for Optimal Performance

• We will standardize the features


using the StandardScaler
class from scikit-learn’s
preprocessing module

• Using the fit method,


StandardScaler estimated the
parameters µ (sample mean) and
σ (standard deviation) for each
feature dimension from the
training data.

• By calling the transform method,


we then standardized the training
data using those estimated
parameters µ and σ
Training the Perceptron
Most algorithms in scikit-learn already
support multiclass classi cation by
default via the One-vs.-Rest (OvR)
method, which allows us to feed the
three ower classes to the perceptron all
at once

C1 C1

C2 C2
NOT
C1
C3 C3

OvR
fl
fi
Prediction

• The results show that the perceptron misclassi es 4 out of the 45 ower test
samples.

• That is, misclassi cation error on the test dataset is 0.089 or 8.9%
• Instead of the misclassi cation error, many machine learning practitioners report
the classi cation accuracy of a model, which is simply calculated as follows:
• 1 - misclassification error = 0.911 or 91.1%.
fi
fi
fi
fi
fl
Scikit-learn Accuracy

• Scikit-learn also implements a large variety of di erent performance metrics


that are available via the metrics module.

• For example, we can calculate the classi cation accuracy of the perceptron
on the test set as follows:

fi
ff

You might also like