# N Days_With_Machine_Learning (Part2 )

--

In This Blog , I will write About How to Learn and Master Machine Learning , It will takes from me **N-1** Days , and it will be divided into 6 Parts (Data Preprocessing** **,** Classification** , Regression , Clustering , Artificial Neural networks , Reinforcement learning )

# Day 2 : Classification

In This part I will explain for you what is **Classification** in Machine learning ?

**What is Classification ?**

Classification is one of the most widely used techniques in machine learning, with a broad array of applications, including sentiment analysis, ad targeting, Spam detection, risk assessment, medical diagnosis and image classification.

The core goal of classification is to predict a category or class y from some inputs x.

**Let’s start Building our Model**

Our Problem is To Predict if the Customer will purchase our Product or Not ?

We Have the dataset of the customers with all the necessary data (Age , Estimated_Salary , Gender ,User_Id, and Purchased or not )

Our Mission is Train Machine learning Model with **Logistic_Regression** to predict the action of the customers (To Buy or not To Buy .. )

**What is Logistic Regression ?**

. A

Logistic regressionmaps a continuous x to a “binary” y. We can use

Logistic regressionto make “category” or “true/false” decisions from data.Example of application :

Logistic Regression:Given a set of medical inputs, does a patient have cancer? (Yes/No)

Don’t’ Worry if you don’t like Maths , you are not supposed to know the Mathematics equations

All What we have to do it to know how to implement the Logistic_Regression Classifier with scikit-learn

## Let’ start Coding

Import the necessary Libraries

`# Imporitng the libraries`

import numpy as np

import matplotlib.pyplot as plt

import pandas as pd

Load the Dataset (Social_Network_Ads.csv)

`dataset = pd.read_csv('Social_Network_Ads.csv');`

X = dataset.iloc[:,[2,3]].values

Y = dataset.iloc[:,4].values

We need to Provide 2 Features for our Model : **Age** && **Estimated_Salary**

# Splitting the Data into Training Set and Testing Setfrom sklearn.model_selection import train_test_split

X_Train ,X_Test , Y_Train,Y_Test= train_test_split(X,Y, test_size=0.25,random_state=0)

Now let’s Scale our Data

# Scaling the data *************from sklearn.preprocessing import StandardScaler

scaler = StandardScaler()

X_train = scaler.fit_transform(X_Train)

X_Test =scaler.transform(X_Test)

Now let’s Prepare our Classifier :

`sklearn.linear_model`

.LogisticRegression

and Train it with Our Data (X_Train Y_Train )

from sklearn import linear_model

#Prepare our Classifier*********

classifier = linear_model.LogisticRegression(C=1e5)#Train our classifier

classifier.fit(X_Train,Y_Train);

Now let’s Make Our Prediction with** Classifier.predict**

`y_predicted = classifier.predict(X_Test)`

I tried in This Blog to Explain for You How To make a Machine Learning Model , Train it with Data , and make your **Prediction**

I have used Logistic_Regression as a Classifier , there is other Classifier we can use them for the classification Task like (SVM, Naive-Bayes , Decision_Tree , K-Nearest-Neighbor and Random Forest )

Making mistakes is a lot better than not doing anything

You Can fin the Full code source Here :

Follow me in Twitter for code Updates

Thanks For Your Feed Back