Statinfer

203.6.2 Practice : Simple Classifier

Let's put classifiers into practice

In previous section, we studied about Introduction to SVM

In this practice session we will cover all the things we discussed about simple classifiers in the last post.

LAB: Simple Classifiers

  • Dataset: Fraud Transaction/Transactions_sample.csv
  • Draw a classification graph that shows all the classes
  • Build a logistic regression classifier
  • Draw the classifier on the data plot

Solution

Transactions_sample <- read.csv("C:\\Amrita\\Datavedi\\Fraud Transaction\\Transactions_sample.csv")
head(Transactions_sample)
##      id Total_Amount Tr_Count_week Fraud_id
## 1 16078      7294.60          4.79        0
## 2 41365      7659.53          2.45        0
## 3 11666      8259.29         10.77        0
## 4 11824     11630.25         15.29        1
## 5 36414     12286.63         22.18        1
## 6    90     12783.34         16.34        1
names(Transactions_sample)
## [1] "id"            "Total_Amount"  "Tr_Count_week" "Fraud_id"
library(ggplot2)
ggplot(Transactions_sample)+geom_point(aes(x=Total_Amount,y=Tr_Count_week,color=factor(Fraud_id),shape=factor(Fraud_id)),size=5)

#####Logit model

logit_model<-glm(Fraud_id~Total_Amount+Tr_Count_week,data=Transactions_sample,family=binomial())
logit_model
## 
## Call:  glm(formula = Fraud_id ~ Total_Amount + Tr_Count_week, family = binomial(), 
##     data = Transactions_sample)
## 
## Coefficients:
##   (Intercept)   Total_Amount  Tr_Count_week  
##    -26.148132       0.002534       0.108896  
## 
## Degrees of Freedom: 209 Total (i.e. Null);  207 Residual
## Null Deviance:       291.1 
## Residual Deviance: 16.85     AIC: 22.85
###The classifier slope & intercept
coef(logit_model)
##   (Intercept)  Total_Amount Tr_Count_week 
## -26.148131643   0.002533707   0.108895819
coef(logit_model)[1]
## (Intercept) 
##   -26.14813
coef(logit_model)[2]
## Total_Amount 
##  0.002533707
coef(logit_model)[3]
## Tr_Count_week 
##     0.1088958
logit_slope <- coef(logit_model)[2]/(-coef(logit_model)[3])
logit_intercept<- coef(logit_model)[1]/(-coef(logit_model)[3]) 

###The classifier diagram

base<-ggplot(Transactions_sample)+geom_point(aes(x=Total_Amount,y=Tr_Count_week,color=factor(Fraud_id),shape=factor(Fraud_id)),size=5)
base+geom_abline(intercept = logit_intercept , slope = logit_slope, color = "red", size = 2) 

 

The next post is about SVM Algorithm.

0 responses on "203.6.2 Practice : Simple Classifier"

Leave a Message

Blog Posts

Hurry up!!!

"use coupon code for FLAT 30% discount"  datascientistoffer        ___________________________________      Subscribe to our youtube channel. Get access to video tutorials.                

Contact Us

Statinfer Software Solutions#647 2nd floor 1st Main, Indira Nagar 1st Stage, 100 feet road,Indranagar Bangalore,Karnataka, Pin code:-560038 Landmarks: Opp. Namma Metro Pillar 48.

Connect with us

linkin fn twitter g

How to become a Data Scientist.?

top