My First Machine learning program

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

What is this

This image explain the Process of Machine learning program

Types of Machine learning :

Supervised learning :

There is 3 steps for Creating Supervised Learning Model :

  • Build the Model
  • Train the Model
  • Test the Model

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 :

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

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 ,

Part2:

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

check by taping python in terminal

python

python installed in linux

What is Sickit-learn ?

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

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

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