R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

library(readr)
credit <- read.csv("C:/Users/nirma/Downloads/credit.csv", stringsAsFactors=TRUE)
View(credit)
#entropy
ColorG<--((1/3*log2(1/3)+2/3*log2(2/3)))
ColorG
## [1] 0.9182958
ColorY<--((8/13*log2(8/13)+5/13*log2(5/13)))
ColorY
## [1] 0.9612366
#ATTRIBUTE ENTROPY
str(credit)
## 'data.frame':    1000 obs. of  17 variables:
##  $ checking_balance    : Factor w/ 4 levels "< 0 DM","> 200 DM",..: 1 3 4 1 1 4 4 3 4 3 ...
##  $ months_loan_duration: int  6 48 12 42 24 36 24 36 12 30 ...
##  $ credit_history      : Factor w/ 5 levels "critical","good",..: 1 2 1 2 4 2 2 2 2 1 ...
##  $ purpose             : Factor w/ 6 levels "business","car",..: 5 5 4 5 2 4 5 2 5 2 ...
##  $ amount              : int  1169 5951 2096 7882 4870 9055 2835 6948 3059 5234 ...
##  $ savings_balance     : Factor w/ 5 levels "< 100 DM","> 1000 DM",..: 5 1 1 1 1 5 4 1 2 1 ...
##  $ employment_duration : Factor w/ 5 levels "< 1 year","> 7 years",..: 2 3 4 4 3 3 2 3 4 5 ...
##  $ percent_of_income   : int  4 2 2 2 3 2 3 2 2 4 ...
##  $ years_at_residence  : int  4 2 3 4 4 4 4 2 4 2 ...
##  $ age                 : int  67 22 49 45 53 35 53 35 61 28 ...
##  $ other_credit        : Factor w/ 3 levels "bank","none",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ housing             : Factor w/ 3 levels "other","own",..: 2 2 2 1 1 1 2 3 2 2 ...
##  $ existing_loans_count: int  2 1 1 1 2 1 1 1 1 2 ...
##  $ job                 : Factor w/ 4 levels "management","skilled",..: 2 2 4 2 2 4 2 1 4 1 ...
##  $ dependents          : int  1 1 2 2 2 2 1 1 1 1 ...
##  $ phone               : Factor w/ 2 levels "no","yes": 2 1 1 1 1 2 1 2 1 1 ...
##  $ default             : Factor w/ 2 levels "no","yes": 1 2 1 1 2 1 1 1 1 2 ...
credit<-credit[-1001,]
credit[155, 1]=as.factor("1 - 200 DM")
credit[155,1]
## [1] 1 - 200 DM
## Levels: < 0 DM > 200 DM 1 - 200 DM unknown
table(credit$checking_balance)
## 
##     < 0 DM   > 200 DM 1 - 200 DM    unknown 
##        274         63        269        394
prop.table(table(credit$checking_balance))
## 
##     < 0 DM   > 200 DM 1 - 200 DM    unknown 
##      0.274      0.063      0.269      0.394
str(credit$checking_balance)
##  Factor w/ 4 levels "< 0 DM","> 200 DM",..: 1 3 4 1 1 4 4 3 4 3 ...
table(credit$savings_balance)
## 
##      < 100 DM     > 1000 DM  100 - 500 DM 500 - 1000 DM       unknown 
##           603            48           103            63           183
prop.table(table(credit$savings_balance))
## 
##      < 100 DM     > 1000 DM  100 - 500 DM 500 - 1000 DM       unknown 
##         0.603         0.048         0.103         0.063         0.183
summary(credit$months_loan_duration)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     4.0    12.0    18.0    20.9    24.0    72.0
summary(credit$amount)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     250    1366    2320    3271    3972   18424
str(credit$default)
##  Factor w/ 2 levels "no","yes": 1 2 1 1 2 1 1 1 1 2 ...
credit$default<-factor(credit$default)
str(credit$default)
##  Factor w/ 2 levels "no","yes": 1 2 1 1 2 1 1 1 1 2 ...
table(credit$default)
## 
##  no yes 
## 700 300
prop.table(table(credit$default))
## 
##  no yes 
## 0.7 0.3
set.seed(12345)
credit_rand<-credit[order(runif(1000)), ]
head(credit_rand)
##     checking_balance months_loan_duration credit_history              purpose
## 14            < 0 DM                   24       critical                  car
## 448       1 - 200 DM                    7           good furniture/appliances
## 697       1 - 200 DM                   12           good furniture/appliances
## 32            < 0 DM                   24           good furniture/appliances
## 196       1 - 200 DM                    9       critical            education
## 83           unknown                   18           good             business
##     amount savings_balance employment_duration percent_of_income
## 14    1199        < 100 DM           > 7 years                 4
## 448   2576        < 100 DM         1 - 4 years                 2
## 697   1103        < 100 DM         4 - 7 years                 4
## 32    4020        < 100 DM         1 - 4 years                 2
## 196   1501        < 100 DM           > 7 years                 2
## 83    1568    100 - 500 DM         1 - 4 years                 3
##     years_at_residence age other_credit housing existing_loans_count        job
## 14                   4  60         none     own                    2  unskilled
## 448                  2  35         none     own                    1    skilled
## 697                  3  29         none     own                    2    skilled
## 32                   2  27        store     own                    1    skilled
## 196                  3  34         none     own                    2 management
## 83                   4  24         none    rent                    1  unskilled
##     dependents phone default
## 14           1    no     yes
## 448          1    no      no
## 697          1    no      no
## 32           1    no      no
## 196          1   yes     yes
## 83           1    no      no
credit_train <- credit_rand[1:900, ]
credit_test <- credit_rand[901:1000, ]
library(C50)
## Warning: package 'C50' was built under R version 4.3.3
m<-C5.0(credit_train, credit_train$default, trials=1, costs=NULL)
m
## 
## Call:
## C5.0.default(x = credit_train, y = credit_train$default, trials = 1, costs
##  = NULL)
## 
## Classification Tree
## Number of samples: 900 
## Number of predictors: 17 
## 
## Tree size: 2 
## 
## Non-standard options: attempt to group attributes

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.