09.10.2023 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 3

Supervised Learning Using Python

The following code is an example of the Naive Bayes classification of

numerical data:

#Import Library of Gaussian Naive Bayes model

from sklearn.naive_bayes import GaussianNB

import numpy as np

#assigning predictor and target variables

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

y = df[target class column ]

X = df[ col1, col2 ..]

#Create a Gaussian Classifier

model = GaussianNB()

# Train the model using the training sets

model.fit(X, y)

#Predict Output

print model.predict([input array])

Note You’ll see another example of the Naive Bayes classifier in the

“Sentiment Analysis” section.

Support Vector Machine

If you look at Figure 3-2, you can easily understand that the circle and

square points are linearly separable in two dimensions (x1, x2). But they

are not linearly separable in either dimension x1 or x2. The support vector

machine algorithm works on this theory. It increases the dimension of

the data until points are linearly separable. Once that is done, you have

62

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

Saved successfully!

Ooh no, something went wrong!