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:

install.packages("caret")
## Installing package into 'C:/Users/lunaa/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'caret' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'caret'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\lunaa\AppData\Local\R\win-library\4.3\00LOCK\caret\libs\x64\caret.dll
## to C:\Users\lunaa\AppData\Local\R\win-library\4.3\caret\libs\x64\caret.dll:
## Permission denied
## Warning: restored 'caret'
## 
## The downloaded binary packages are in
##  C:\Users\lunaa\AppData\Local\Temp\RtmpSwHLNL\downloaded_packages
library(caret)
## Warning: package 'caret' was built under R version 4.3.2
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.3.2
## Loading required package: lattice
data("GermanCredit")

GermanCredit$Class <-  GermanCredit$Class == "Good"
str(GermanCredit)
## 'data.frame':    1000 obs. of  62 variables:
##  $ Duration                              : int  6 48 12 42 24 36 24 36 12 30 ...
##  $ Amount                                : int  1169 5951 2096 7882 4870 9055 2835 6948 3059 5234 ...
##  $ InstallmentRatePercentage             : int  4 2 2 2 3 2 3 2 2 4 ...
##  $ ResidenceDuration                     : int  4 2 3 4 4 4 4 2 4 2 ...
##  $ Age                                   : int  67 22 49 45 53 35 53 35 61 28 ...
##  $ NumberExistingCredits                 : int  2 1 1 1 2 1 1 1 1 2 ...
##  $ NumberPeopleMaintenance               : int  1 1 2 2 2 2 1 1 1 1 ...
##  $ Telephone                             : num  0 1 1 1 1 0 1 0 1 1 ...
##  $ ForeignWorker                         : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ Class                                 : logi  TRUE FALSE TRUE TRUE FALSE TRUE ...
##  $ CheckingAccountStatus.lt.0            : num  1 0 0 1 1 0 0 0 0 0 ...
##  $ CheckingAccountStatus.0.to.200        : num  0 1 0 0 0 0 0 1 0 1 ...
##  $ CheckingAccountStatus.gt.200          : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CheckingAccountStatus.none            : num  0 0 1 0 0 1 1 0 1 0 ...
##  $ CreditHistory.NoCredit.AllPaid        : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CreditHistory.ThisBank.AllPaid        : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CreditHistory.PaidDuly                : num  0 1 0 1 0 1 1 1 1 0 ...
##  $ CreditHistory.Delay                   : num  0 0 0 0 1 0 0 0 0 0 ...
##  $ CreditHistory.Critical                : num  1 0 1 0 0 0 0 0 0 1 ...
##  $ Purpose.NewCar                        : num  0 0 0 0 1 0 0 0 0 1 ...
##  $ Purpose.UsedCar                       : num  0 0 0 0 0 0 0 1 0 0 ...
##  $ Purpose.Furniture.Equipment           : num  0 0 0 1 0 0 1 0 0 0 ...
##  $ Purpose.Radio.Television              : num  1 1 0 0 0 0 0 0 1 0 ...
##  $ Purpose.DomesticAppliance             : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Purpose.Repairs                       : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Purpose.Education                     : num  0 0 1 0 0 1 0 0 0 0 ...
##  $ Purpose.Vacation                      : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Purpose.Retraining                    : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Purpose.Business                      : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Purpose.Other                         : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ SavingsAccountBonds.lt.100            : num  0 1 1 1 1 0 0 1 0 1 ...
##  $ SavingsAccountBonds.100.to.500        : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ SavingsAccountBonds.500.to.1000       : num  0 0 0 0 0 0 1 0 0 0 ...
##  $ SavingsAccountBonds.gt.1000           : num  0 0 0 0 0 0 0 0 1 0 ...
##  $ SavingsAccountBonds.Unknown           : num  1 0 0 0 0 1 0 0 0 0 ...
##  $ EmploymentDuration.lt.1               : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ EmploymentDuration.1.to.4             : num  0 1 0 0 1 1 0 1 0 0 ...
##  $ EmploymentDuration.4.to.7             : num  0 0 1 1 0 0 0 0 1 0 ...
##  $ EmploymentDuration.gt.7               : num  1 0 0 0 0 0 1 0 0 0 ...
##  $ EmploymentDuration.Unemployed         : num  0 0 0 0 0 0 0 0 0 1 ...
##  $ Personal.Male.Divorced.Seperated      : num  0 0 0 0 0 0 0 0 1 0 ...
##  $ Personal.Female.NotSingle             : num  0 1 0 0 0 0 0 0 0 0 ...
##  $ Personal.Male.Single                  : num  1 0 1 1 1 1 1 1 0 0 ...
##  $ Personal.Male.Married.Widowed         : num  0 0 0 0 0 0 0 0 0 1 ...
##  $ Personal.Female.Single                : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ OtherDebtorsGuarantors.None           : num  1 1 1 0 1 1 1 1 1 1 ...
##  $ OtherDebtorsGuarantors.CoApplicant    : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ OtherDebtorsGuarantors.Guarantor      : num  0 0 0 1 0 0 0 0 0 0 ...
##  $ Property.RealEstate                   : num  1 1 1 0 0 0 0 0 1 0 ...
##  $ Property.Insurance                    : num  0 0 0 1 0 0 1 0 0 0 ...
##  $ Property.CarOther                     : num  0 0 0 0 0 0 0 1 0 1 ...
##  $ Property.Unknown                      : num  0 0 0 0 1 1 0 0 0 0 ...
##  $ OtherInstallmentPlans.Bank            : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ OtherInstallmentPlans.Stores          : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ OtherInstallmentPlans.None            : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ Housing.Rent                          : num  0 0 0 0 0 0 0 1 0 0 ...
##  $ Housing.Own                           : num  1 1 1 0 0 0 1 0 1 1 ...
##  $ Housing.ForFree                       : num  0 0 0 1 1 1 0 0 0 0 ...
##  $ Job.UnemployedUnskilled               : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Job.UnskilledResident                 : num  0 0 1 0 0 1 0 0 1 0 ...
##  $ Job.SkilledEmployee                   : num  1 1 0 1 1 0 1 0 0 0 ...
##  $ Job.Management.SelfEmp.HighlyQualified: num  0 0 0 0 0 0 0 1 0 1 ...
GermanCredit = GermanCredit[,-c(14,19,27,30,35,40,44,45,48,52,55,58,62)]

Observation: By removing unnecessary columns we will be able to focus on the information 2on hand that will help us anaylze any significant correlations.

summary(GermanCredit)
##     Duration        Amount      InstallmentRatePercentage ResidenceDuration
##  Min.   : 4.0   Min.   :  250   Min.   :1.000             Min.   :1.000    
##  1st Qu.:12.0   1st Qu.: 1366   1st Qu.:2.000             1st Qu.:2.000    
##  Median :18.0   Median : 2320   Median :3.000             Median :3.000    
##  Mean   :20.9   Mean   : 3271   Mean   :2.973             Mean   :2.845    
##  3rd Qu.:24.0   3rd Qu.: 3972   3rd Qu.:4.000             3rd Qu.:4.000    
##  Max.   :72.0   Max.   :18424   Max.   :4.000             Max.   :4.000    
##       Age        NumberExistingCredits NumberPeopleMaintenance   Telephone    
##  Min.   :19.00   Min.   :1.000         Min.   :1.000           Min.   :0.000  
##  1st Qu.:27.00   1st Qu.:1.000         1st Qu.:1.000           1st Qu.:0.000  
##  Median :33.00   Median :1.000         Median :1.000           Median :1.000  
##  Mean   :35.55   Mean   :1.407         Mean   :1.155           Mean   :0.596  
##  3rd Qu.:42.00   3rd Qu.:2.000         3rd Qu.:1.000           3rd Qu.:1.000  
##  Max.   :75.00   Max.   :4.000         Max.   :2.000           Max.   :1.000  
##  ForeignWorker     Class         CheckingAccountStatus.lt.0
##  Min.   :0.000   Mode :logical   Min.   :0.000             
##  1st Qu.:1.000   FALSE:300       1st Qu.:0.000             
##  Median :1.000   TRUE :700       Median :0.000             
##  Mean   :0.963                   Mean   :0.274             
##  3rd Qu.:1.000                   3rd Qu.:1.000             
##  Max.   :1.000                   Max.   :1.000             
##  CheckingAccountStatus.0.to.200 CheckingAccountStatus.gt.200
##  Min.   :0.000                  Min.   :0.000               
##  1st Qu.:0.000                  1st Qu.:0.000               
##  Median :0.000                  Median :0.000               
##  Mean   :0.269                  Mean   :0.063               
##  3rd Qu.:1.000                  3rd Qu.:0.000               
##  Max.   :1.000                  Max.   :1.000               
##  CreditHistory.NoCredit.AllPaid CreditHistory.ThisBank.AllPaid
##  Min.   :0.00                   Min.   :0.000                 
##  1st Qu.:0.00                   1st Qu.:0.000                 
##  Median :0.00                   Median :0.000                 
##  Mean   :0.04                   Mean   :0.049                 
##  3rd Qu.:0.00                   3rd Qu.:0.000                 
##  Max.   :1.00                   Max.   :1.000                 
##  CreditHistory.PaidDuly CreditHistory.Delay Purpose.NewCar  Purpose.UsedCar
##  Min.   :0.00           Min.   :0.000       Min.   :0.000   Min.   :0.000  
##  1st Qu.:0.00           1st Qu.:0.000       1st Qu.:0.000   1st Qu.:0.000  
##  Median :1.00           Median :0.000       Median :0.000   Median :0.000  
##  Mean   :0.53           Mean   :0.088       Mean   :0.234   Mean   :0.103  
##  3rd Qu.:1.00           3rd Qu.:0.000       3rd Qu.:0.000   3rd Qu.:0.000  
##  Max.   :1.00           Max.   :1.000       Max.   :1.000   Max.   :1.000  
##  Purpose.Furniture.Equipment Purpose.Radio.Television Purpose.DomesticAppliance
##  Min.   :0.000               Min.   :0.00             Min.   :0.000            
##  1st Qu.:0.000               1st Qu.:0.00             1st Qu.:0.000            
##  Median :0.000               Median :0.00             Median :0.000            
##  Mean   :0.181               Mean   :0.28             Mean   :0.012            
##  3rd Qu.:0.000               3rd Qu.:1.00             3rd Qu.:0.000            
##  Max.   :1.000               Max.   :1.00             Max.   :1.000            
##  Purpose.Repairs Purpose.Education Purpose.Retraining Purpose.Business
##  Min.   :0.000   Min.   :0.00      Min.   :0.000      Min.   :0.000   
##  1st Qu.:0.000   1st Qu.:0.00      1st Qu.:0.000      1st Qu.:0.000   
##  Median :0.000   Median :0.00      Median :0.000      Median :0.000   
##  Mean   :0.022   Mean   :0.05      Mean   :0.009      Mean   :0.097   
##  3rd Qu.:0.000   3rd Qu.:0.00      3rd Qu.:0.000      3rd Qu.:0.000   
##  Max.   :1.000   Max.   :1.00      Max.   :1.000      Max.   :1.000   
##  SavingsAccountBonds.lt.100 SavingsAccountBonds.100.to.500
##  Min.   :0.000              Min.   :0.000                 
##  1st Qu.:0.000              1st Qu.:0.000                 
##  Median :1.000              Median :0.000                 
##  Mean   :0.603              Mean   :0.103                 
##  3rd Qu.:1.000              3rd Qu.:0.000                 
##  Max.   :1.000              Max.   :1.000                 
##  SavingsAccountBonds.500.to.1000 SavingsAccountBonds.gt.1000
##  Min.   :0.000                   Min.   :0.000              
##  1st Qu.:0.000                   1st Qu.:0.000              
##  Median :0.000                   Median :0.000              
##  Mean   :0.063                   Mean   :0.048              
##  3rd Qu.:0.000                   3rd Qu.:0.000              
##  Max.   :1.000                   Max.   :1.000              
##  EmploymentDuration.lt.1 EmploymentDuration.1.to.4 EmploymentDuration.4.to.7
##  Min.   :0.000           Min.   :0.000             Min.   :0.000            
##  1st Qu.:0.000           1st Qu.:0.000             1st Qu.:0.000            
##  Median :0.000           Median :0.000             Median :0.000            
##  Mean   :0.172           Mean   :0.339             Mean   :0.174            
##  3rd Qu.:0.000           3rd Qu.:1.000             3rd Qu.:0.000            
##  Max.   :1.000           Max.   :1.000             Max.   :1.000            
##  EmploymentDuration.gt.7 Personal.Male.Divorced.Seperated
##  Min.   :0.000           Min.   :0.00                    
##  1st Qu.:0.000           1st Qu.:0.00                    
##  Median :0.000           Median :0.00                    
##  Mean   :0.253           Mean   :0.05                    
##  3rd Qu.:1.000           3rd Qu.:0.00                    
##  Max.   :1.000           Max.   :1.00                    
##  Personal.Female.NotSingle Personal.Male.Single OtherDebtorsGuarantors.None
##  Min.   :0.00              Min.   :0.000        Min.   :0.000              
##  1st Qu.:0.00              1st Qu.:0.000        1st Qu.:1.000              
##  Median :0.00              Median :1.000        Median :1.000              
##  Mean   :0.31              Mean   :0.548        Mean   :0.907              
##  3rd Qu.:1.00              3rd Qu.:1.000        3rd Qu.:1.000              
##  Max.   :1.00              Max.   :1.000        Max.   :1.000              
##  OtherDebtorsGuarantors.CoApplicant Property.RealEstate Property.Insurance
##  Min.   :0.000                      Min.   :0.000       Min.   :0.000     
##  1st Qu.:0.000                      1st Qu.:0.000       1st Qu.:0.000     
##  Median :0.000                      Median :0.000       Median :0.000     
##  Mean   :0.041                      Mean   :0.282       Mean   :0.232     
##  3rd Qu.:0.000                      3rd Qu.:1.000       3rd Qu.:0.000     
##  Max.   :1.000                      Max.   :1.000       Max.   :1.000     
##  Property.CarOther OtherInstallmentPlans.Bank OtherInstallmentPlans.Stores
##  Min.   :0.000     Min.   :0.000              Min.   :0.000               
##  1st Qu.:0.000     1st Qu.:0.000              1st Qu.:0.000               
##  Median :0.000     Median :0.000              Median :0.000               
##  Mean   :0.332     Mean   :0.139              Mean   :0.047               
##  3rd Qu.:1.000     3rd Qu.:0.000              3rd Qu.:0.000               
##  Max.   :1.000     Max.   :1.000              Max.   :1.000               
##   Housing.Rent    Housing.Own    Job.UnemployedUnskilled Job.UnskilledResident
##  Min.   :0.000   Min.   :0.000   Min.   :0.000           Min.   :0.0          
##  1st Qu.:0.000   1st Qu.:0.000   1st Qu.:0.000           1st Qu.:0.0          
##  Median :0.000   Median :1.000   Median :0.000           Median :0.0          
##  Mean   :0.179   Mean   :0.713   Mean   :0.022           Mean   :0.2          
##  3rd Qu.:0.000   3rd Qu.:1.000   3rd Qu.:0.000           3rd Qu.:0.0          
##  Max.   :1.000   Max.   :1.000   Max.   :1.000           Max.   :1.0          
##  Job.SkilledEmployee
##  Min.   :0.00       
##  1st Qu.:0.00       
##  Median :1.00       
##  Mean   :0.63       
##  3rd Qu.:1.00       
##  Max.   :1.00

Observation: By using the summary function we will be able to determine a summary of the dataset. Thus, as shown on the tables, we can determine that the mimnimum age group of credit would be individuals at the age of 19 and the maximum age group would be 75 years of age.

colSums(is.na(GermanCredit))
##                           Duration                             Amount 
##                                  0                                  0 
##          InstallmentRatePercentage                  ResidenceDuration 
##                                  0                                  0 
##                                Age              NumberExistingCredits 
##                                  0                                  0 
##            NumberPeopleMaintenance                          Telephone 
##                                  0                                  0 
##                      ForeignWorker                              Class 
##                                  0                                  0 
##         CheckingAccountStatus.lt.0     CheckingAccountStatus.0.to.200 
##                                  0                                  0 
##       CheckingAccountStatus.gt.200     CreditHistory.NoCredit.AllPaid 
##                                  0                                  0 
##     CreditHistory.ThisBank.AllPaid             CreditHistory.PaidDuly 
##                                  0                                  0 
##                CreditHistory.Delay                     Purpose.NewCar 
##                                  0                                  0 
##                    Purpose.UsedCar        Purpose.Furniture.Equipment 
##                                  0                                  0 
##           Purpose.Radio.Television          Purpose.DomesticAppliance 
##                                  0                                  0 
##                    Purpose.Repairs                  Purpose.Education 
##                                  0                                  0 
##                 Purpose.Retraining                   Purpose.Business 
##                                  0                                  0 
##         SavingsAccountBonds.lt.100     SavingsAccountBonds.100.to.500 
##                                  0                                  0 
##    SavingsAccountBonds.500.to.1000        SavingsAccountBonds.gt.1000 
##                                  0                                  0 
##            EmploymentDuration.lt.1          EmploymentDuration.1.to.4 
##                                  0                                  0 
##          EmploymentDuration.4.to.7            EmploymentDuration.gt.7 
##                                  0                                  0 
##   Personal.Male.Divorced.Seperated          Personal.Female.NotSingle 
##                                  0                                  0 
##               Personal.Male.Single        OtherDebtorsGuarantors.None 
##                                  0                                  0 
## OtherDebtorsGuarantors.CoApplicant                Property.RealEstate 
##                                  0                                  0 
##                 Property.Insurance                  Property.CarOther 
##                                  0                                  0 
##         OtherInstallmentPlans.Bank       OtherInstallmentPlans.Stores 
##                                  0                                  0 
##                       Housing.Rent                        Housing.Own 
##                                  0                                  0 
##            Job.UnemployedUnskilled              Job.UnskilledResident 
##                                  0                                  0 
##                Job.SkilledEmployee 
##                                  0

Observation: In order for us to get a better grasp of the data being provided we are going to determine if there are any missing values within the data that may affect our analysis.It seems that many of the variables have missing values. The variable that will mos tliekly prove to be useless would be savingsaccountsbonds due to the high quantity of missing values. It is missing 500 values thus making this variable unreliable.

ggplot(GermanCredit, aes(x = GermanCredit$Class)) +
  geom_bar(stat = "count", fill = "blue", alpha = 0.7) +
  ggtitle("Distribution class of credit (GOOD= TRUE, BAD= FALSE)") +
  xlab("Month") +
  ylab("Class")
## Warning: Use of `GermanCredit$Class` is discouraged.
## ℹ Use `Class` instead.

Observation: The ggplot does demonstrates that there are more goods than bads; however, I do not understadn what it is referring to. What does it mean by good or bad? as in maybe the variables? what would the 0.7 be referring too? Is it like a constant value? or can it be changed?

boxplot(GermanCredit, las =2, cex.axis=0.7 )

Observation: I tried using a histogram but i completely failed at using one. Thus jus referred to the box plot. There seems to be an abnormality with the variable of amount but for some reason it does not appear on the box plot but I went bakck to the data and that blank space should be “Amount”.

hist(GermanCredit$Amount)

set.seed(2023)
Measure <- sample(1:nrow(GermanCredit),nrow(GermanCredit)*0.80)
GermanCredit.train = GermanCredit[Measure,]
GermanCredit.test = GermanCredit[-Measure,]

Observation: The data is being split into train and test

str(GermanCredit)
## 'data.frame':    1000 obs. of  49 variables:
##  $ Duration                          : int  6 48 12 42 24 36 24 36 12 30 ...
##  $ Amount                            : int  1169 5951 2096 7882 4870 9055 2835 6948 3059 5234 ...
##  $ InstallmentRatePercentage         : int  4 2 2 2 3 2 3 2 2 4 ...
##  $ ResidenceDuration                 : int  4 2 3 4 4 4 4 2 4 2 ...
##  $ Age                               : int  67 22 49 45 53 35 53 35 61 28 ...
##  $ NumberExistingCredits             : int  2 1 1 1 2 1 1 1 1 2 ...
##  $ NumberPeopleMaintenance           : int  1 1 2 2 2 2 1 1 1 1 ...
##  $ Telephone                         : num  0 1 1 1 1 0 1 0 1 1 ...
##  $ ForeignWorker                     : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ Class                             : logi  TRUE FALSE TRUE TRUE FALSE TRUE ...
##  $ CheckingAccountStatus.lt.0        : num  1 0 0 1 1 0 0 0 0 0 ...
##  $ CheckingAccountStatus.0.to.200    : num  0 1 0 0 0 0 0 1 0 1 ...
##  $ CheckingAccountStatus.gt.200      : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CreditHistory.NoCredit.AllPaid    : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CreditHistory.ThisBank.AllPaid    : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CreditHistory.PaidDuly            : num  0 1 0 1 0 1 1 1 1 0 ...
##  $ CreditHistory.Delay               : num  0 0 0 0 1 0 0 0 0 0 ...
##  $ Purpose.NewCar                    : num  0 0 0 0 1 0 0 0 0 1 ...
##  $ Purpose.UsedCar                   : num  0 0 0 0 0 0 0 1 0 0 ...
##  $ Purpose.Furniture.Equipment       : num  0 0 0 1 0 0 1 0 0 0 ...
##  $ Purpose.Radio.Television          : num  1 1 0 0 0 0 0 0 1 0 ...
##  $ Purpose.DomesticAppliance         : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Purpose.Repairs                   : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Purpose.Education                 : num  0 0 1 0 0 1 0 0 0 0 ...
##  $ Purpose.Retraining                : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Purpose.Business                  : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ SavingsAccountBonds.lt.100        : num  0 1 1 1 1 0 0 1 0 1 ...
##  $ SavingsAccountBonds.100.to.500    : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ SavingsAccountBonds.500.to.1000   : num  0 0 0 0 0 0 1 0 0 0 ...
##  $ SavingsAccountBonds.gt.1000       : num  0 0 0 0 0 0 0 0 1 0 ...
##  $ EmploymentDuration.lt.1           : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ EmploymentDuration.1.to.4         : num  0 1 0 0 1 1 0 1 0 0 ...
##  $ EmploymentDuration.4.to.7         : num  0 0 1 1 0 0 0 0 1 0 ...
##  $ EmploymentDuration.gt.7           : num  1 0 0 0 0 0 1 0 0 0 ...
##  $ Personal.Male.Divorced.Seperated  : num  0 0 0 0 0 0 0 0 1 0 ...
##  $ Personal.Female.NotSingle         : num  0 1 0 0 0 0 0 0 0 0 ...
##  $ Personal.Male.Single              : num  1 0 1 1 1 1 1 1 0 0 ...
##  $ OtherDebtorsGuarantors.None       : num  1 1 1 0 1 1 1 1 1 1 ...
##  $ OtherDebtorsGuarantors.CoApplicant: num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Property.RealEstate               : num  1 1 1 0 0 0 0 0 1 0 ...
##  $ Property.Insurance                : num  0 0 0 1 0 0 1 0 0 0 ...
##  $ Property.CarOther                 : num  0 0 0 0 0 0 0 1 0 1 ...
##  $ OtherInstallmentPlans.Bank        : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ OtherInstallmentPlans.Stores      : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Housing.Rent                      : num  0 0 0 0 0 0 0 1 0 0 ...
##  $ Housing.Own                       : num  1 1 1 0 0 0 1 0 1 1 ...
##  $ Job.UnemployedUnskilled           : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Job.UnskilledResident             : num  0 0 1 0 0 1 0 0 1 0 ...
##  $ Job.SkilledEmployee               : num  1 1 0 1 1 0 1 0 0 0 ...
model <- glm(Class ~ ., data = GermanCredit.train, family = binomial)

Observation: used glm in order to fit the data set.

summary(model)
## 
## Call:
## glm(formula = Class ~ ., family = binomial, data = GermanCredit.train)
## 
## Coefficients:
##                                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                         7.948e+00  1.620e+00   4.908 9.22e-07 ***
## Duration                           -2.465e-02  1.027e-02  -2.401  0.01636 *  
## Amount                             -1.206e-04  4.943e-05  -2.440  0.01467 *  
## InstallmentRatePercentage          -2.766e-01  9.796e-02  -2.823  0.00476 ** 
## ResidenceDuration                   4.616e-02  9.831e-02   0.469  0.63872    
## Age                                 1.982e-02  1.046e-02   1.896  0.05802 .  
## NumberExistingCredits              -2.741e-01  2.145e-01  -1.278  0.20142    
## NumberPeopleMaintenance            -1.388e-01  2.898e-01  -0.479  0.63190    
## Telephone                          -2.586e-01  2.242e-01  -1.153  0.24877    
## ForeignWorker                      -1.789e+00  8.309e-01  -2.153  0.03132 *  
## CheckingAccountStatus.lt.0         -1.944e+00  2.646e-01  -7.347 2.02e-13 ***
## CheckingAccountStatus.0.to.200     -1.278e+00  2.551e-01  -5.009 5.46e-07 ***
## CheckingAccountStatus.gt.200       -5.367e-01  4.445e-01  -1.208  0.22724    
## CreditHistory.NoCredit.AllPaid     -1.284e+00  4.801e-01  -2.674  0.00750 ** 
## CreditHistory.ThisBank.AllPaid     -1.436e+00  4.997e-01  -2.873  0.00407 ** 
## CreditHistory.PaidDuly             -7.179e-01  2.865e-01  -2.506  0.01221 *  
## CreditHistory.Delay                -5.630e-01  3.726e-01  -1.511  0.13081    
## Purpose.NewCar                     -1.917e+00  8.668e-01  -2.212  0.02697 *  
## Purpose.UsedCar                    -2.727e-01  8.931e-01  -0.305  0.76006    
## Purpose.Furniture.Equipment        -1.069e+00  8.737e-01  -1.223  0.22118    
## Purpose.Radio.Television           -1.054e+00  8.812e-01  -1.196  0.23171    
## Purpose.DomesticAppliance          -1.109e+00  1.220e+00  -0.909  0.36321    
## Purpose.Repairs                    -1.992e+00  1.035e+00  -1.924  0.05433 .  
## Purpose.Education                  -1.896e+00  9.500e-01  -1.996  0.04595 *  
## Purpose.Retraining                 -1.045e+00  1.507e+00  -0.694  0.48796    
## Purpose.Business                   -1.240e+00  8.975e-01  -1.381  0.16721    
## SavingsAccountBonds.lt.100         -9.516e-01  2.975e-01  -3.199  0.00138 ** 
## SavingsAccountBonds.100.to.500     -7.571e-01  3.877e-01  -1.953  0.05083 .  
## SavingsAccountBonds.500.to.1000    -3.102e-01  5.274e-01  -0.588  0.55639    
## SavingsAccountBonds.gt.1000        -2.349e-01  5.947e-01  -0.395  0.69284    
## EmploymentDuration.lt.1             2.255e-01  4.925e-01   0.458  0.64711    
## EmploymentDuration.1.to.4           2.978e-01  4.682e-01   0.636  0.52473    
## EmploymentDuration.4.to.7           8.561e-01  5.057e-01   1.693  0.09045 .  
## EmploymentDuration.gt.7             3.178e-01  4.724e-01   0.673  0.50108    
## Personal.Male.Divorced.Seperated   -5.419e-01  4.982e-01  -1.088  0.27668    
## Personal.Female.NotSingle          -2.182e-01  3.492e-01  -0.625  0.53197    
## Personal.Male.Single                2.917e-01  3.523e-01   0.828  0.40770    
## OtherDebtorsGuarantors.None        -7.453e-01  4.707e-01  -1.583  0.11339    
## OtherDebtorsGuarantors.CoApplicant -1.243e+00  6.380e-01  -1.948  0.05138 .  
## Property.RealEstate                 8.035e-01  4.647e-01   1.729  0.08381 .  
## Property.Insurance                  6.041e-01  4.511e-01   1.339  0.18050    
## Property.CarOther                   4.111e-01  4.378e-01   0.939  0.34776    
## OtherInstallmentPlans.Bank         -5.736e-01  2.706e-01  -2.120  0.03401 *  
## OtherInstallmentPlans.Stores       -4.597e-01  4.649e-01  -0.989  0.32276    
## Housing.Rent                       -5.839e-01  5.256e-01  -1.111  0.26656    
## Housing.Own                        -7.262e-02  4.909e-01  -0.148  0.88240    
## Job.UnemployedUnskilled             9.950e-01  8.532e-01   1.166  0.24352    
## Job.UnskilledResident               1.006e-01  3.978e-01   0.253  0.80027    
## Job.SkilledEmployee                 1.195e-02  3.242e-01   0.037  0.97060    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 980.75  on 799  degrees of freedom
## Residual deviance: 717.58  on 751  degrees of freedom
## AIC: 815.58
## 
## Number of Fisher Scoring iterations: 5

Observation:By using class and binomial, family I was able to determine any significant factors. It shows that checking account status is very significant.

predictions <- predict(model, newdata = GermanCredit.test, type = "response")

Observations:By using this fromat we will be able to predict points of the data.

predicted_classes <- ifelse(predictions > 0.5, 1, 0)

Observations:By setting up the trainging set now we will be able to predict probabilities.

probabilities <- predict(model, newdata = GermanCredit.test, type = "response")

Observations: Once we have established the predicted classes then we need to make sure to change this to a predicted function in order to get any probabilities.

head(probabilities)
##         1        14        15        17        22        23 
## 0.9607537 0.5583378 0.2273744 0.9783679 0.8002388 0.9197085

Observations:These are the probabilities given and as shown on line 96 our prediction have to be between 0.5 and 1.

optimal_cutoff <- 0.5

Observation: By placing the optimal cutoff we will be able to signify a minimum of the data.

train_probabilities <- predict(model, newdata = GermanCredit.train, type = "response")

Observation: by using train probabilities and the predict model we will be able to get a response of wether it is a true or a false.

train_predicted_classes <- ifelse(train_probabilities > optimal_cutoff, 1, 0)
conf_matrix_train <- table(Actual = GermanCredit.train$Class, Predicted = train_predicted_classes)

Observation: By having established the confusion matrix and using the predicted train class we will be able to get the predicted values into a matrix an dget a response of true or false.

conf_matrix_train
##        Predicted
## Actual    0   1
##   FALSE 134 108
##   TRUE   61 497

Observation: We got an actual response and a predicted response and thus allowing us to analyze wether it is a true or a false posibility.

MR_train <- (conf_matrix_train[1, 2] + conf_matrix_train[2, 1]) / sum(conf_matrix_train)
MR_train
## [1] 0.21125

Observation: I used this in order to calculate the misclassification rate of the data which is the matrix.

library(pROC)
## Type 'citation("pROC")' for a citation.
## 
## Attaching package: 'pROC'
## The following objects are masked from 'package:stats':
## 
##     cov, smooth, var
train_probabilities <- predict(model, newdata = GermanCredit.train, type = "response")
roc_curve <- roc(GermanCredit.train$Class, train_probabilities)
## Setting levels: control = FALSE, case = TRUE
## Setting direction: controls < cases
plot(roc_curve, main = "ROC Curve for Training Set", col = "blue", lwd = 2)

Observation: There seems to be something wrong however I dont not understand the error.

print(roc_curve)
## 
## Call:
## roc.default(response = GermanCredit.train$Class, predictor = train_probabilities)
## 
## Data: train_probabilities in 242 controls (GermanCredit.train$Class FALSE) < 558 cases (GermanCredit.train$Class TRUE).
## Area under the curve: 0.8358
test_probabilities <- predict(model, newdata = GermanCredit.test, type = "response")
test_predicted_classes <- ifelse(test_probabilities > optimal_cutoff, 1, 0)
conf_matrix_test <- table(Actual = GermanCredit.test$Class, Predicted = test_predicted_classes)
conf_matrix_test
##        Predicted
## Actual    0   1
##   FALSE  31  27
##   TRUE   23 119

ObservationL: By using the confusion matrix test we were able to determine the matrix of the preditcted class.

MR_test <- (conf_matrix_test[1, 2] + conf_matrix_test[2, 1]) / sum(conf_matrix_test)
MR_test
## [1] 0.25

Observation: The MR test was ran and came out to 0.25 and was less than as placed in the matrix test.

test_probabilities <- predict(model, newdata = GermanCredit.test, type = "response")
roc_curve_test <- roc(GermanCredit.test$Class, test_probabilities)
## Setting levels: control = FALSE, case = TRUE
## Setting direction: controls < cases
plot(roc_curve_test, main = "ROC Curve for Test Set", col = "green", lwd = 2)

print(roc_curve_test)
## 
## Call:
## roc.default(response = GermanCredit.test$Class, predictor = test_probabilities)
## 
## Data: test_probabilities in 58 controls (GermanCredit.test$Class FALSE) < 142 cases (GermanCredit.test$Class TRUE).
## Area under the curve: 0.8091
weight_good_to_bad <- 1
weight_bad_to_good <- 5

Observation: Frist we have to assign the weights

Including Plots

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.