09.10.2023 Views

Advanced Data Analytics Using Python_ With Machine Learning, Deep Learning and NLP Examples ( 2023)

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3

Supervised Learning Using Python

to find two parallel hyperplanes that separate the data. This planes are

known as the margin. The algorithm chose the margins in such a way that

the distance between them is the maximum. That’s why it is the maximum

margin. The plane, which is at the middle of these two margins or at equal

distance between them, is known as an optimal hyperplane that is used to

classify the test data (see Figure 3-2). The separator can be nonlinear also.

X 2

X 1

Optimal hyperplane

Maximum

margin

Figure 3-2. Support vector machine

The following code is an example of doing support vector machine

classification using Python:

from sklearn import svm

df = pd.read_csv('csv file path', index_col=0)

y = df[target class column ]

X = df[ col1, col2 ..]

63

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!