k-nn classifier for image classification

15
CORRELATING TEXT AND IMAGE IN SOCIAL MEDIA DATA By Raj Pratim Bhattacharya 510814001 Subhadeep Dey 510814008 IT Dept.

Upload: raj-pratim-bhattacharya

Post on 16-Apr-2017

136 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: K-NN Classifier For Image Classification

CORRELATING TEXT AND IMAGE IN SOCIAL MEDIA DATAByRaj Pratim Bhattacharya 510814001Subhadeep Dey 510814008IT Dept.

Page 2: K-NN Classifier For Image Classification

Getting Data from Twitter.

The Data is Scraped from Twitter

Page 3: K-NN Classifier For Image Classification

K-NN classifier for image classification

Page 4: K-NN Classifier For Image Classification

How does the k-NN classifier work?

The k-Nearest Neighbor classifier is by far the most simple machine learning/image classification algorithm.

Inside, this algorithm simply relies on the distance between feature vectors.

We have the labels associated with each image so we can predict and return an actual category for the image.

Page 5: K-NN Classifier For Image Classification

Implementing k-NN for image classificationProgram takes an input image ,resizes it to a fixed width and height ( size ), then flattens the RGB pixel intensities into a single list of numbers.

Input image will be shrunk to 32 x 32 pixels, and

given three channels for each Red, Green, and Blue component

Respectively , our output “feature vector” will be a list of 32 x 32 x 3 = 3,072 numbers.

Page 6: K-NN Classifier For Image Classification

First, we convert our image to the HSV color space on Line 19. We then apply the cv2. calcHist function to compute a 3D color histogram for the image

Given 8 bins for each of the hue, saturation, and value channels respectively, our final feature vector is of size 8 x 8 x 8 = 512, thus our image is characterized by a 512-d feature vector

Page 7: K-NN Classifier For Image Classification
Page 8: K-NN Classifier For Image Classification

3 d histogram

Page 9: K-NN Classifier For Image Classification
Page 10: K-NN Classifier For Image Classification

K-NN image classification resultsWe get an accuracy of 72.4% in classifying.

Page 11: K-NN Classifier For Image Classification

Some ObservationsWe have tested the same data set over another algorithm convolutional neural network

We expected a lot more accuracy has 72.4% as it’s a true learning network than 72.4%, but to our amaze we only got 59.6%

We tested both algorithm over another data set kragle dog’s vs cat dataset which consists of 25000 labeled images of both dogs and cats it’s a huge data of 537 MB

Results were 57.8% for KNN classifier and 76 % for CNN

Whereas our data set gives 72.4 % KNN classifier and 59.6%

For CNN

Page 12: K-NN Classifier For Image Classification

As we compare the data sets

Politics images

Sposts Images

Page 13: K-NN Classifier For Image Classification
Page 14: K-NN Classifier For Image Classification

Comparison between Dataset

Variance is very high i.e it’s domain is very high.

CNN module can’t learn enough to give good accuracy .

Where as KNN model just need to compare and get nearest neighbour so it perfoms comparitively well in this case.

Where as in the Dogs vs Cats data set data variance is quite low

it’s a huge data set of 25k images so CNN model can learn well and performs comparatively better here

Page 15: K-NN Classifier For Image Classification

CONCLUSION

When dataset is small and contains lot of variance knn algorithm works better than the learning algorithms as it don’t learn anything just compare .

When dataset is large and contains less noise and less variance learning algorithms like Convolutional Neural Network(CNN) works better.