My First Machine learning program

Image for post
Image for post

In This Blog , I will explain for you how to write your first classifier in machine learning

Before we start , let’s explain what is really machine learning , types of machine learning and famous uses cases of it

What is machine learning ?

Machine learning is the science of creating algorithms and program which learn on their own , they do not need human to become better

Image for post
Image for post
What is this

This image explain the Process of Machine learning program

Image for post
Image for post

Types of Machine learning :

Supervised learning :

There is 3 steps for Creating Supervised Learning Model :

  • Build the Model
  • Train the Model
  • Test the Model
Image for post
Image for post

And there is 2 Types of Supervised learning :

. “Classification” : we train our model how to classify something into some class

This is the List of famous algorithms used for classification :

  1. Support vector machines (SVM)
  2. Naïve Bayes classifier.
  3. Decision trees
  4. Nearest neighbors (KNN)
  5. Neural Networks
  6. ……

“Regression” : we use regression when we need to deal with data that the output value is real value such as “Age” , “Weight” , “House Price “ etc …

There are many famous algorithms used for Regression :

  • Linear regression
  • Nonlinear regression
  • Generalized linear models
  • Support Vector Regression (SVR)
  • Back-Propagation Neural Network (BPNN)
  • Partial Least Squares (PLS)
  • Multiple Linear Regression (MLR)

Unsupervised Learning :

It differed from supervised learning the labels are not given , our machine should learn through observation

Unsupervised leaning problems can be divided into clustering and associations

Clustering : is type of unsupervised learning that refers to segmentation and learning about characteristics in the data through algorithms

There are many algorithms used for Clustering :

  • K-Means Clustering
  • Hierarchical Clustering
  • Density based Clustering

Association : “is the process to train our machine to discover rules that describe large points of data “

Use Cases of Machine learning :

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
  • Spam Filters
  • Recommendation System
  • Chatbots
  • fraud detection
  • Self-Drive Cars
  • Self-Drive Drone
  • Image Recognition
  • Speech Recognition
  • Object Detection
  • Cancer Detection
  • and many other …..
Image for post
Image for post

This BuzzWord “Machine learning “touch every aspect of our lives , we deal with it without being consciously about it .

We don’t ask ourselves how the Youtube Recommendation videos work .

How Facebook friends suggestion find us ,

Or how we find related answers in Quora ,

Image for post
Image for post

Part2:

Image for post
Image for post

Before we start , you should have python 3.x or 2.x installed in your Computer

check by taping python in terminal

python

Image for post
Image for post
python installed in linux

What is Sickit-learn ?

Image for post
Image for post
David Cournapeau

We need to install Sickit-learn and required modules by following this commands :

sudo apt-get update  
sudo apt-get install --no-install-recommends python2.7-minimal python2.7
sudo apt-get install python-numpy python-scipy
pip install -U scikit-learn

Now After installing the necessary packages and libraries , let’s start creating our first classifier :

we will create a program that can predict an image which digit it represents

Image for post
Image for post
Training and testing process

Loading our Dataset

#import our datasest from sklearn
from sklearn import datasets

# Load in the `digits` data
digits = datasets.load_digits()

# Print the `digits` data
print(digits.data)

What is dataset ?

dataset is a dictionary-like object that holds all the data and some metadata about the data”

Learning and Predicting

#import our Classifier avalaible
from sklearn.svm import SVC
# Create a classifier: a support vector classifier
classifier = SVC(gamma=0.001)

for predicting we will use the SUPPORT VECTOR MACHINE algorithm

# turn the data in a (samples, feature) matrix:
n_samples = len(digits.images)
data = digits.images.reshape((n_samples, -1))

Train our Model with the “fit method”,

# We train our model with the first half of data
classifier.fit(data[:n_samples // 2], digits.target[:n_samples // 2])

Now we will test our classifier by predicting the second half of our data

expected = digits.target[n_samples // 2:]
predicted = classifier.predict(data[n_samples // 2:])

Now let’s Evaluate our model

print("Classification report for classifier %s:\n%s\n"
% (classifier, metrics.classification_report(expected, predicted)))
print("Confusion matrix:\n%s" % metrics.confusion_matrix(expected, predicted))

I hope that was helpful ! you can find the full code here and you can Follow me in Twitter to check updates about code

Image for post
Image for post

Written by

<script>alert('try your best')</script>

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store