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

Image Recognition

Image recognition is a common example of image classification. It is easy

to use in Python by applying the opencv library. Here is the sample code:

faceCascade=cv2.CascadeClassifier(cascPath)

image = cv2.imread(imagePath)

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

faces = faceCascade.detectMultiScale(

gray,

scaleFactor=1.1,

minNeighbors=5,

minSize=(30, 30),

flags = cv2.cv.CV_HAAR_SCALE_IMAGE

)

print"Found {0} faces!".format(len(faces))

Regression with Python

Regression realizes a variable as a linear or nonlinear polynomial of a set of

independent variables.

Here is an interesting use case: what is the sales price of a product that

maximizes its profit? This is a million-dollar question for any merchant.

The question is not straightforward. Maximizing the sales price may

not result in maximizing the profit because increasing the sales price

sometimes decreases the sales volume, which decreases the total profit.

So, there will be an optimized value of sales price for which the profit will

be at the maximum.

There is N number of records of the transaction with M number of

features called F1, F2, ... Fm (sales price, buy price, cash back, SKU, order

date, and so on). You have to find a subset of K(K<M) features that have an

67

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

Saved successfully!

Ooh no, something went wrong!