library(readr)
## Warning: package 'readr' was built under R version 4.3.2
credit <- read_csv("credit.csv")
## Rows: 1001 Columns: 21
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (13): checking_balance, credit_history, purpose, savings_balance, employ...
## dbl (8): months_loan_duration, amount, installment_rate, residence_history,...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(credit)
#CLASS 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)
## spc_tbl_ [1,001 × 21] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ checking_balance : chr [1:1001] "unknown" "1 - 200 DM" "< 0 DM" "< 0 DM" ...
## $ months_loan_duration: num [1:1001] 6 9 6 12 6 6 6 12 15 12 ...
## $ credit_history : chr [1:1001] "critical" "repaid" "critical" "fully repaid this bank" ...
## $ purpose : chr [1:1001] "car (new)" "car (new)" "radio/tv" "retraining" ...
## $ amount : num [1:1001] 250 276 338 339 343 362 368 385 392 409 ...
## $ savings_balance : chr [1:1001] "> 1000 DM" "< 100 DM" "501 - 1000 DM" "< 100 DM" ...
## $ employment_length : chr [1:1001] "1 - 4 yrs" "1 - 4 yrs" "> 7 yrs" "> 7 yrs" ...
## $ installment_rate : num [1:1001] 2 4 4 4 4 4 4 4 4 3 ...
## $ personal_status : chr [1:1001] "female" "married male" "single male" "married male" ...
## $ other_debtors : chr [1:1001] "none" "none" "none" "none" ...
## $ residence_history : num [1:1001] 2 4 4 1 1 4 4 3 4 3 ...
## $ property : chr [1:1001] "real estate" "real estate" "other" "other" ...
## $ age : num [1:1001] 41 22 52 45 27 52 38 58 23 42 ...
## $ installment_plan : chr [1:1001] "bank" "none" "none" "bank" ...
## $ housing : chr [1:1001] "own" "rent" "own" "own" ...
## $ existing_credits : num [1:1001] 2 1 2 1 1 2 1 4 1 2 ...
## $ default : num [1:1001] 1 1 1 1 1 1 1 1 1 1 ...
## $ dependents : num [1:1001] 1 1 1 1 1 1 1 1 1 1 ...
## $ telephone : chr [1:1001] "none" "none" "none" "none" ...
## $ foreign_worker : chr [1:1001] "yes" "yes" "yes" "yes" ...
## $ job : chr [1:1001] "unskilled resident" "unskilled resident" "skilled employee" "unskilled resident" ...
## - attr(*, "spec")=
## .. cols(
## .. checking_balance = col_character(),
## .. months_loan_duration = col_double(),
## .. credit_history = col_character(),
## .. purpose = col_character(),
## .. amount = col_double(),
## .. savings_balance = col_character(),
## .. employment_length = col_character(),
## .. installment_rate = col_double(),
## .. personal_status = col_character(),
## .. other_debtors = col_character(),
## .. residence_history = col_double(),
## .. property = col_character(),
## .. age = col_double(),
## .. installment_plan = col_character(),
## .. housing = col_character(),
## .. existing_credits = col_double(),
## .. default = col_double(),
## .. dependents = col_double(),
## .. telephone = col_character(),
## .. foreign_worker = col_character(),
## .. job = col_character()
## .. )
## - attr(*, "problems")=<externalptr>
credit<-credit[-1001,]
credit[155, 1]=as.factor("1 - 200 DM")
credit[155,1]
## # A tibble: 1 × 1
## checking_balance
## <chr>
## 1 1 - 200 DM
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)
## chr [1:1000] "unknown" "1 - 200 DM" "< 0 DM" "< 0 DM" "< 0 DM" ...
table(credit$savings_balance)
##
## < 100 DM > 1000 DM 101 - 500 DM 501 - 1000 DM unknown
## 603 48 103 63 183
prop.table(table(credit$savings_balance))
##
## < 100 DM > 1000 DM 101 - 500 DM 501 - 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)
## num [1:1000] 1 1 1 1 1 1 1 1 1 1 ...
credit$default<-factor(credit$default)
str(credit$default)
## Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
table(credit$default)
##
## 1 2
## 700 300
prop.table(table(credit$default))
##
## 1 2
## 0.7 0.3
set.seed(12345)
credit_rand<-credit[order(runif(1000)), ]
head(credit_rand)
## # A tibble: 6 × 21
## checking_balance months_loan_duration credit_history purpose amount
## <chr> <dbl> <chr> <chr> <dbl>
## 1 > 200 DM 6 fully repaid this bank education 433
## 2 unknown 6 critical car (new) 2080
## 3 < 0 DM 12 critical radio/tv 3573
## 4 1 - 200 DM 12 repaid car (new) 640
## 5 unknown 24 repaid business 1258
## 6 unknown 18 repaid radio/tv 866
## # ℹ 16 more variables: savings_balance <chr>, employment_length <chr>,
## # installment_rate <dbl>, personal_status <chr>, other_debtors <chr>,
## # residence_history <dbl>, property <chr>, age <dbl>, installment_plan <chr>,
## # housing <chr>, existing_credits <dbl>, default <fct>, dependents <dbl>,
## # telephone <chr>, foreign_worker <chr>, job <chr>
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: 21
##
## Tree size: 2
##
## Non-standard options: attempt to group attributes
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.