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:

options(repos = c(CRAN = "https://cran.rstudio.com"))
install.packages("e1071")
## Installing package into 'C:/Users/lunaa/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'e1071' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'e1071'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\lunaa\AppData\Local\R\win-library\4.3\00LOCK\e1071\libs\x64\e1071.dll
## to C:\Users\lunaa\AppData\Local\R\win-library\4.3\e1071\libs\x64\e1071.dll:
## Permission denied
## Warning: restored 'e1071'
## 
## The downloaded binary packages are in
##  C:\Users\lunaa\AppData\Local\Temp\RtmpUrLPyd\downloaded_packages
install.packages('caret')

Task1: Data Preparation

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 <-  as.numeric(GermanCredit$Class == "Good")
GermanCredit$Class <- as.factor(GermanCredit$Class)
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                                 : Factor w/ 2 levels "0","1": 2 1 2 2 1 2 2 2 2 1 ...
##  $ 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 ...

There seems to be 1000 obervations and 62 varibles in the data set

GermanCredit = GermanCredit[,-c(14,19,27,30,35,40,44,45,48,52,55,58,62)]

2. Explore the dataset to understand its structure.

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                             : Factor w/ 2 levels "0","1": 2 1 2 2 1 2 2 2 2 1 ...
##  $ 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 ...
set.seed(2023)
n <- 40
x1 <- rnorm(n)
x2 <- 0.75 * x1 + rnorm(n)
y <- ifelse(x2 > 0.5, 1, 0)
data <- data.frame(y=as.factor(y),x1=x1,x2=x2)
head(data)
##   y          x1         x2
## 1 0 -0.08378436  0.3654983
## 2 0 -0.98294375 -0.3184814
## 3 0 -1.87506732 -0.9708340
## 4 0 -0.18614466 -0.3438706
## 5 0 -0.63348570 -0.1727608
## 6 1  1.09079746  1.5124559

By using the seed(2023) and by dividing the data between x1 and x2 we are able to find seperate factors. In rows 1-5 there seems to be no change in the Y factor; however, on row 6 we see that there is a change from 0 to 1. The main differnces that can be obersved would be that on rows 1-5 have negative values and row number 6 has a positive value which might have made a difference.

library(ggplot2)
plot <- ggplot(data, aes(x = x1, y = x2, color = factor(y))) +
  geom_point(size = 2) +
  ggtitle("SVM Hyperplane in 2D Space") +
  xlab("x1") +
  ylab("x2") +
  scale_color_discrete(name = "y", labels = c("0", "1"))
plot

## It can be observed that the graph is demonstrating blue and orange points and can be determined that quadrant one and two has only blue dots and quadrant 3 and 4 has orange dots. The margin of this SVM graph is very low; however, does have various support vectors.

w <- c(0.168,2.565)
b <- 1.29

plot + geom_abline(slope = w[1] / w[2], intercept = b / w[2])

## This graphs helps be more accurate with the margin and weight of each category.

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

set.seed(2023)
ind <- sample(2, nrow(GermanCredit), replace=TRUE, prob=c(0.8, 0.2))
training_data <- GermanCredit[ind==1,]
test_data <- GermanCredit[ind==2,]
svm_model <- svm(Purpose.NewCar ~ ., data = training_data, kernel = 'linear')
## Warning in svm.default(x, y, scale = scale, ..., na.action = na.action):
## Variable(s) 'Purpose.Vacation' and 'Personal.Female.Single' constant. Cannot
## scale data.
summary(svm_model)
## 
## Call:
## svm(formula = Purpose.NewCar ~ ., data = training_data, kernel = "linear")
## 
## 
## Parameters:
##    SVM-Type:  eps-regression 
##  SVM-Kernel:  linear 
##        cost:  1 
##       gamma:  0.01612903 
##     epsilon:  0.1 
## 
## 
## Number of Support Vectors:  685
predictions <- predict(svm_model, training_data)

table(true = training_data$Purpose.NewCar, pred = predictions)
##     pred
## true -36.7740055503197 -34.7994886817283 -33.1142612280197 -31.7493565859146
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -31.4417948903389 -30.2211185278244 -29.9788105072326 -29.3986489953346
##    0                 1                 1                 0                 1
##    1                 0                 0                 1                 0
##     pred
## true -29.2018300624437 -29.0918252052612 -28.6188870550937 -28.3179293455429
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -27.484594482357 -27.4668486745901 -27.4429699512071 -27.1345004917927
##    0                0                 1                 0                 1
##    1                1                 0                 1                 0
##     pred
## true -26.9626491399355 -26.9091167332477 -25.976481545145 -25.0269855441398
##    0                 0                 1                1                 1
##    1                 1                 0                0                 0
##     pred
## true -24.9140011252708 -24.6849956991024 -24.1958756925411 -24.1025046141691
##    0                 1                 1                 0                 1
##    1                 0                 0                 1                 0
##     pred
## true -23.7639610947914 -23.3707294048614 -23.3008378626652 -22.1535739483185
##    0                 0                 1                 0                 1
##    1                 1                 0                 1                 0
##     pred
## true -21.7359588922806 -21.612671244318 -21.4409896613903 -21.3556233228988
##    0                 1                1                 1                 1
##    1                 0                0                 0                 0
##     pred
## true -20.9929908992595 -20.8876628609247 -20.2859939219303 -20.1071724029131
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -20.0212299706287 -19.8032215865202 -19.57685144561 -19.555085215146
##    0                 0                 1               1                0
##    1                 1                 0               0                1
##     pred
## true -18.8690645428247 -18.866592097456 -18.5105341555424 -18.5095052601642
##    0                 1                1                 1                 1
##    1                 0                0                 0                 0
##     pred
## true -18.4770078243561 -18.2202722610779 -17.9070946307726 -17.8301656128711
##    0                 1                 0                 1                 1
##    1                 0                 1                 0                 0
##     pred
## true -17.1303743304558 -16.9104061307258 -16.4328355373688 -16.3742868037767
##    0                 0                 1                 1                 0
##    1                 1                 0                 0                 1
##     pred
## true -15.7662055970974 -15.6597211839504 -15.563855092401 -15.530697497899
##    0                 1                 1                1                1
##    1                 0                 0                0                0
##     pred
## true -15.1917842881627 -15.1774351181335 -15.0450965644665 -14.9070583464451
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -14.6548717798538 -14.0329163255043 -13.9739437730856 -13.9459624471016
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -13.914875927741 -13.6036921845622 -13.2858172686643 -13.2783322216816
##    0                0                 1                 1                 1
##    1                1                 0                 0                 0
##     pred
## true -13.2055951984472 -13.1873314784713 -12.8831171573944 -12.8475617648907
##    0                 1                 1                 1                 0
##    1                 0                 0                 0                 1
##     pred
## true -12.7343989195175 -12.695199373538 -12.4500341670461 -12.432690750236
##    0                 0                1                 1                1
##    1                 1                0                 0                0
##     pred
## true -12.2752133490391 -12.0296438591428 -11.8941836537666 -11.8314818175382
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -11.7907775672025 -11.7866700621195 -11.7527136834211 -11.4570512058086
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -11.3195829572029 -11.3194325746841 -11.2998624922581 -11.0900460960216
##    0                 0                 1                 0                 1
##    1                 1                 0                 1                 0
##     pred
## true -11.0826533468313 -10.7332205729432 -10.7157428966708 -10.713109556014
##    0                 1                 0                 0                1
##    1                 0                 1                 1                0
##     pred
## true -10.5832626404114 -10.5442263068504 -10.5390643210954 -10.5057060303039
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -10.397960427577 -10.390045407588 -10.3835279004521 -10.3425923319406
##    0                0                1                 1                 0
##    1                1                0                 0                 1
##     pred
## true -10.3120089949913 -10.2552416132636 -10.172646182949 -10.1725877107925
##    0                 1                 0                1                 1
##    1                 0                 1                0                 0
##     pred
## true -10.1219537513203 -10.0789478005714 -10.0425183804579 -10.0096100898332
##    0                 1                 1                 1                 0
##    1                 0                 0                 0                 1
##     pred
## true -9.99405088591049 -9.95389314311216 -9.90488170402716 -9.90478970425795
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -9.72954212444494 -9.67867118435572 -9.65897266882132 -9.63683943765829
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -9.51615611034105 -9.46058167087505 -9.4480868609495 -9.29846857803533
##    0                 0                 0                1                 0
##    1                 1                 1                0                 1
##     pred
## true -9.2859056772537 -9.2504078330345 -9.18225449266503 -9.06180928962896
##    0                1                1                 1                 1
##    1                0                0                 0                 0
##     pred
## true -8.97378866689871 -8.88126829581926 -8.73798825162123 -8.64559981542299
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -8.59350982623766 -8.56598572748373 -8.53722934740255 -8.40584155114959
##    0                 1                 1                 0                 1
##    1                 0                 0                 1                 0
##     pred
## true -8.27440984862516 -8.16218114959667 -8.00452924090097 -8.00182866620491
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -7.83263488429258 -7.80888387876223 -7.80789333152245 -7.76804471331308
##    0                 0                 1                 1                 1
##    1                 1                 0                 0                 0
##     pred
## true -7.63280631172131 -7.58540830331514 -7.48904469924639 -7.45946239250372
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -7.34837953316639 -7.33941842930983 -7.29067536013792 -7.27066383826206
##    0                 1                 1                 0                 1
##    1                 0                 0                 1                 0
##     pred
## true -7.25226522552441 -7.2109948651738 -7.17006825971077 -7.16160650866697
##    0                 1                1                 1                 1
##    1                 0                0                 0                 0
##     pred
## true -7.04979215877722 -6.75459371822546 -6.74579634087751 -6.71363232600162
##    0                 1                 1                 0                 1
##    1                 0                 0                 1                 0
##     pred
## true -6.67661606090734 -6.49093878584574 -6.30159148144195 -6.28147010820578
##    0                 0                 0                 1                 1
##    1                 1                 1                 0                 0
##     pred
## true -6.23408254551361 -6.20914498286913 -6.20244326757858 -6.15034260916183
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -6.11122402864168 -6.05485229509542 -5.99986385124395 -5.91986541765402
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -5.89748674201439 -5.86237708794544 -5.81765349524687 -5.78024030047129
##    0                 1                 1                 0                 1
##    1                 0                 0                 1                 0
##     pred
## true -5.77204470651815 -5.76466844918797 -5.74424861686895 -5.69870134758423
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -5.65128173249433 -5.59933092760513 -5.53909378069113 -5.4627386363096
##    0                 1                 1                 1                0
##    1                 0                 0                 0                1
##     pred
## true -5.43382156210611 -5.37799451815556 -5.37410016673277 -5.30102718191812
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -5.25427121984432 -5.23954489770005 -5.02558935003946 -4.95227511542509
##    0                 1                 1                 1                 0
##    1                 0                 0                 0                 1
##     pred
## true -4.91435356753538 -4.8071830825753 -4.77811522724698 -4.77751766460607
##    0                 1                1                 1                 1
##    1                 0                0                 0                 0
##     pred
## true -4.74006055238316 -4.72783763277004 -4.7084531219549 -4.69701813476751
##    0                 1                 1                0                 1
##    1                 0                 0                1                 0
##     pred
## true -4.66594381945799 -4.60521283316086 -4.53344014602373 -4.51026060002516
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -4.43639713468621 -4.40977572965095 -4.39901231544683 -4.34221910255621
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -4.34082209634254 -4.28539960401724 -4.25438727753828 -4.22426504212091
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -4.2190864862747 -4.13609677123497 -4.07610120939682 -4.0663433106489
##    0                1                 1                 1                1
##    1                0                 0                 0                0
##     pred
## true -4.0376145871229 -4.00692451315592 -3.93252563791941 -3.84522869008253
##    0                1                 1                 1                 1
##    1                0                 0                 0                 0
##     pred
## true -3.83446641581724 -3.75957134681414 -3.73871053325603 -3.73138632195661
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -3.72872948589395 -3.7266670571513 -3.61193493323992 -3.60885686370204
##    0                 0                0                 1                 1
##    1                 1                1                 0                 0
##     pred
## true -3.569416339869 -3.55876348483036 -3.54048712866972 -3.52568398358891
##    0               1                 1                 0                 1
##    1               0                 0                 1                 0
##     pred
## true -3.51301262098024 -3.50629408972929 -3.50058487373064 -3.46989303397606
##    0                 1                 0                 1                 0
##    1                 0                 1                 0                 1
##     pred
## true -3.44945701527069 -3.35275456624697 -3.26226644533346 -3.233514706964
##    0                 1                 1                 1               1
##    1                 0                 0                 0               0
##     pred
## true -3.20395991894076 -3.18122758286665 -3.15634906234811 -3.15326444002459
##    0                 1                 0                 0                 1
##    1                 0                 1                 1                 0
##     pred
## true -3.04471227096985 -3.03407127725552 -3.00049366372297 -2.93825244473885
##    0                 1                 1                 0                 1
##    1                 0                 0                 1                 0
##     pred
## true -2.93181442039679 -2.90956826078365 -2.8770526902623 -2.7846083300061
##    0                 1                 1                1                1
##    1                 0                 0                0                0
##     pred
## true -2.72147809284399 -2.71543745266865 -2.71492121684025 -2.61220123189161
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -2.59583821463058 -2.58575603681276 -2.58095885383556 -2.54716435017655
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -2.5312072591729 -2.4349851341791 -2.37422385009597 -2.35228265392254
##    0                1                0                 1                 1
##    1                0                1                 0                 0
##     pred
## true -2.3318359101064 -2.2477714748926 -2.24311068969438 -2.22554520832966
##    0                1                0                 1                 1
##    1                0                1                 0                 0
##     pred
## true -2.21583720611999 -2.18853391277264 -2.17224529700945 -2.17115234898994
##    0                 0                 1                 1                 1
##    1                 1                 0                 0                 0
##     pred
## true -2.16149513738821 -2.13406674879263 -2.08174128400753 -2.04836131202648
##    0                 1                 0                 1                 1
##    1                 0                 1                 0                 0
##     pred
## true -2.00927636715243 -1.98990532698701 -1.93382184150289 -1.92553457933138
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -1.9206183137245 -1.92030048685739 -1.86316226738165 -1.86228063272903
##    0                1                 1                 0                 1
##    1                0                 0                 1                 0
##     pred
## true -1.85628314631651 -1.85415102111767 -1.83712207096289 -1.83251120651732
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -1.80398638116787 -1.78435140045951 -1.78165006207893 -1.76698467450808
##    0                 0                 1                 1                 0
##    1                 1                 0                 0                 1
##     pred
## true -1.75424355583857 -1.69519848691891 -1.63753957616756 -1.60192927288483
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -1.54919912981461 -1.49279151427219 -1.42385766225527 -1.3578496755905
##    0                 1                 1                 1                1
##    1                 0                 0                 0                0
##     pred
## true -1.35493562685917 -1.35491298081944 -1.34940876382063 -1.34480196925471
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -1.31022531109522 -1.28296931775878 -1.26053363400171 -1.22424756305883
##    0                 1                 1                 0                 1
##    1                 0                 0                 1                 0
##     pred
## true -1.2183039145417 -1.19827847498129 -1.17808299081991 -1.14893256443212
##    0                1                 1                 1                 1
##    1                0                 0                 0                 0
##     pred
## true -1.11652635353277 -1.10725306289862 -1.10036972853015 -1.08416018950413
##    0                 0                 1                 1                 0
##    1                 1                 0                 0                 1
##     pred
## true -1.08335083665917 -1.07821602317164 -1.04249335395763 -1.01586252766321
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -0.999269212955932 -0.960235364163617 -0.943243245954017
##    0                  1                  1                  1
##    1                  0                  0                  0
##     pred
## true -0.943025510186652 -0.893716651374797 -0.864381677830915
##    0                  1                  1                  1
##    1                  0                  0                  0
##     pred
## true -0.834802455628614 -0.815269428665141 -0.787542122776012
##    0                  1                  1                  0
##    1                  0                  0                  1
##     pred
## true -0.768502566391925 -0.751792396778564 -0.735179084712962
##    0                  1                  1                  0
##    1                  0                  0                  1
##     pred
## true -0.718118931526641 -0.683855983788471 -0.652351322943668
##    0                  1                  1                  1
##    1                  0                  0                  0
##     pred
## true -0.650337676877479 -0.649717427218656 -0.641389779175023
##    0                  1                  0                  1
##    1                  0                  1                  0
##     pred
## true -0.622385203266839 -0.621083329791526 -0.601567278975944
##    0                  1                  1                  1
##    1                  0                  0                  0
##     pred
## true -0.581456502328018 -0.570398238847355 -0.567528236085872
##    0                  1                  1                  1
##    1                  0                  0                  0
##     pred
## true -0.556943181330661 -0.547224137360553 -0.541935800934533
##    0                  0                  1                  1
##    1                  1                  0                  0
##     pred
## true -0.530393137956361 -0.524225506360034 -0.490066162670354
##    0                  1                  1                  1
##    1                  0                  0                  0
##     pred
## true -0.464380230183105 -0.396418056810598 -0.355944457823734 -0.35567792447875
##    0                  1                  1                  1                 1
##    1                  0                  0                  0                 0
##     pred
## true -0.331737342650394 -0.297146353299121 -0.295226383382778
##    0                  1                  1                  1
##    1                  0                  0                  0
##     pred
## true -0.257994077528219 -0.236939470643501 -0.236071679169635
##    0                  1                  1                  1
##    1                  0                  0                  0
##     pred
## true -0.217487863624791 -0.205800685460071 -0.185644294495086
##    0                  1                  1                  1
##    1                  0                  0                  0
##     pred
## true -0.153223435754279 -0.146991356635789 -0.10412109958599
##    0                  1                  1                 1
##    1                  0                  0                 0
##     pred
## true -0.0856710182375711 -0.0547603735573094 -0.0411112861580651
##    0                   1                   1                   1
##    1                   0                   0                   0
##     pred
## true -0.0379485109693807 -0.0256936805195611 -0.0101641708857816
##    0                   1                   1                   0
##    1                   0                   0                   1
##     pred
## true -0.00801569538782054 0.00430691299368924 0.00514870939185208
##    0                    1                   1                   1
##    1                    0                   0                   0
##     pred
## true 0.0133835194759566 0.0313318451993663 0.0451290855311353
##    0                  1                  1                  1
##    1                  0                  0                  0
##     pred
## true 0.0822649119548995 0.0836280217521388 0.111644026463528 0.11479790193369
##    0                  1                  1                 0                1
##    1                  0                  0                 1                0
##     pred
## true 0.122479457979699 0.160783205752869 0.178616103356381 0.188553952252169
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true 0.190218370979329 0.192170411919852 0.251630332892438 0.2879517754667
##    0                 1                 1                 1               1
##    1                 0                 0                 0               0
##     pred
## true 0.336449534272452 0.362524089043637 0.372575741832753 0.39678813015451
##    0                 1                 1                 0                0
##    1                 0                 0                 1                1
##     pred
## true 0.413793735777636 0.422141265695592 0.425197665219804 0.43124172148635
##    0                 1                 0                 0                1
##    1                 0                 1                 1                0
##     pred
## true 0.437213034009238 0.491887406086226 0.508168425982495 0.529871114169856
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true 0.622391883855363 0.637376499002476 0.736942191248437 0.738285784249802
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true 0.784702975874444 0.806001231645842 0.818502884929677 0.845384006028672
##    0                 1                 1                 1                 0
##    1                 0                 0                 0                 1
##     pred
## true 0.860769821902414 0.868824184512397 0.880979236786862 0.897532497172852
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true 0.898024324899216 0.898377333407899 0.918523103570243 0.933574382787247
##    0                 1                 1                 1                 0
##    1                 0                 0                 0                 1
##     pred
## true 0.942680378084679 1.00092017335226 1.00135601369073 1.01759477016856
##    0                 1                1                1                1
##    1                 0                0                0                0
##     pred
## true 1.02267401350071 1.06277597380211 1.06584560928275 1.08637357560327
##    0                0                0                1                1
##    1                1                1                0                0
##     pred
## true 1.10801034850409 1.1448447039478 1.16041271445682 1.16418968570759
##    0                1               1                1                1
##    1                0               0                0                0
##     pred
## true 1.20318811816504 1.20992830452849 1.24800086451103 1.25196931195786
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 1.28429763448765 1.29525820874949 1.30094712284734 1.30281662625601
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 1.30664862749507 1.32398526055147 1.32463210133245 1.33327166979541
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 1.3346094755583 1.35464958531191 1.37446616274645 1.37923935857942
##    0               0                1                1                1
##    1               1                0                0                0
##     pred
## true 1.38732357007792 1.38973191810181 1.40707363990476 1.42726006416013
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 1.43511452024211 1.46253606361677 1.47560471353461 1.48480018657972
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 1.49684853163888 1.54623367694547 1.55340768454005 1.55466623661449
##    0                1                0                1                0
##    1                0                1                0                1
##     pred
## true 1.55543668625285 1.5875681160145 1.59423548412849 1.61081958991816
##    0                1               1                0                1
##    1                0               0                1                0
##     pred
## true 1.62487625015308 1.64018283096482 1.64187534583141 1.6604162162297
##    0                1                0                0               1
##    1                0                1                1               0
##     pred
## true 1.67787149233152 1.72853528020312 1.75878096056511 1.78961477485826
##    0                1                1                0                1
##    1                0                0                1                0
##     pred
## true 1.79199826401999 1.81765025538733 1.82292481010189 1.82989387643864
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 1.84180302602579 1.86738582757642 1.86818553937008 1.87380245943894
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 1.92086758894255 1.92427950130184 1.92764144447972 2.03024221268823
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 2.03454653603365 2.03834914100697 2.06056817305615 2.08780694437553
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 2.09215955120852 2.10338233468463 2.10932295454075 2.15375659299423
##    0                1                1                1                0
##    1                0                0                0                1
##     pred
## true 2.19228867871096 2.19358810094525 2.22296478470196 2.23829248278742
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 2.24413201642563 2.25132090282967 2.26338246149351 2.28063146827151
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 2.29176371974279 2.29816220757892 2.31722948012282 2.34171823469331
##    0                0                1                1                0
##    1                1                0                0                1
##     pred
## true 2.38633517978122 2.39071093184282 2.42431769949724 2.44649846536448
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 2.45039550644686 2.45302047265102 2.46927747373809 2.47096081135203
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 2.47408206445505 2.48727672976782 2.50354206991722 2.51088362616827
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 2.51613695604136 2.54542879444887 2.61024114919235 2.61906346177091
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 2.6345580449455 2.63910972384145 2.6420184640341 2.66177463961174
##    0               0                1               1                1
##    1               1                0               0                0
##     pred
## true 2.69022423086097 2.69487612751653 2.71796330307951 2.79708827716639
##    0                1                0                1                1
##    1                0                1                0                0
##     pred
## true 2.79847429377367 2.82322075647642 2.83112919760277 2.83321279717018
##    0                0                1                1                1
##    1                1                0                0                0
##     pred
## true 2.85465823543598 2.88976009247233 2.89363530335357 2.89924648088743
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 2.90218735915949 2.9336183528543 2.94548431841065 2.95412284192969
##    0                1               1                1                1
##    1                0               0                0                0
##     pred
## true 2.96990624499847 2.97374025416901 3.00456471984615 3.02450858858754
##    0                1                1                1                0
##    1                0                0                0                1
##     pred
## true 3.04883482178082 3.04995921311309 3.06519245413472 3.06563809384932
##    0                0                1                1                1
##    1                1                0                0                0
##     pred
## true 3.09433861320247 3.10699793008496 3.11169536096384 3.13413835001518
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 3.14028076884677 3.1493356568866 3.18802625370552 3.18886326310565
##    0                1               1                0                1
##    1                0               0                1                0
##     pred
## true 3.20055705366065 3.20784230959942 3.21183479261925 3.24516338167121
##    0                1                0                1                1
##    1                0                1                0                0
##     pred
## true 3.26458511558702 3.26678698939612 3.26924443860879 3.27982929778626
##    0                0                1                0                1
##    1                1                0                1                0
##     pred
## true 3.28211132121613 3.28467467856934 3.28565046434631 3.29440842253496
##    0                1                0                1                1
##    1                0                1                0                0
##     pred
## true 3.29493801725437 3.30780263488521 3.31156303418209 3.32170337868263
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 3.32229383346965 3.39879697990944 3.40846142788758 3.40863964391281
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 3.45636378658344 3.46409743895163 3.49374648240735 3.51405199674298
##    0                1                1                0                1
##    1                0                0                1                0
##     pred
## true 3.53592347038319 3.55839633253743 3.569480083523 3.60640723687937
##    0                1                0              1                0
##    1                0                1              0                1
##     pred
## true 3.6179977623873 3.62612321657469 3.63347151187589 3.63480191362431
##    0               1                1                1                1
##    1               0                0                0                0
##     pred
## true 3.65162862521936 3.69605993164112 3.71192987506618 3.71733284426262
##    0                0                1                1                1
##    1                1                0                0                0
##     pred
## true 3.74733490926554 3.7726404188328 3.78807616663506 3.79631680307319
##    0                0               0                1                1
##    1                1               1                0                0
##     pred
## true 3.81081267689695 3.81139623803427 3.83375426811506 3.83769506459465
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 3.8412946989887 3.93253385146489 3.93918324691584 3.95107434002091
##    0               0                0                0                1
##    1               1                1                1                0
##     pred
## true 3.95505982694556 3.96551805605521 4.01036079657604 4.0156901298218
##    0                1                1                1               0
##    1                0                0                0               1
##     pred
## true 4.05306010377934 4.06438254249622 4.06495676433076 4.0777520356827
##    0                1                1                0               0
##    1                0                0                1               1
##     pred
## true 4.07808807921936 4.08105403428306 4.14054921699097 4.14663157669236
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 4.1573968647175 4.16338403766384 4.16492435206999 4.16993052942087
##    0               1                1                1                1
##    1               0                0                0                0
##     pred
## true 4.18996817675759 4.21157247816553 4.22811055426826 4.23835555707445
##    0                1                1                1                0
##    1                0                0                0                1
##     pred
## true 4.23934925032188 4.24463221674194 4.2796036867552 4.2839765219145
##    0                1                1               1               0
##    1                0                0               0               1
##     pred
## true 4.29557083418002 4.30295315814545 4.30891565663149 4.31522626859476
##    0                1                0                1                1
##    1                0                1                0                0
##     pred
## true 4.33234312256207 4.35940086526205 4.36485278104772 4.3857711242639
##    0                1                0                0               1
##    1                0                1                1               0
##     pred
## true 4.40594074187209 4.40737577212383 4.41197468025019 4.4195852732413
##    0                1                0                1               1
##    1                0                1                0               0
##     pred
## true 4.41960656700065 4.42461246309211 4.4250699883454 4.43414818180134
##    0                1                0               0                0
##    1                0                1               1                1
##     pred
## true 4.44970226717522 4.45680513290097 4.46496206392874 4.48656946105291
##    0                0                1                0                0
##    1                1                0                1                1
##     pred
## true 4.5094121458136 4.54458269161512 4.56403639783492 4.6029370525979
##    0               0                1                1               1
##    1               1                0                0               0
##     pred
## true 4.60911849570801 4.62151895520618 4.64078281504442 4.65812139456501
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 4.65862811786463 4.66328052115967 4.66488773060371 4.67724165005018
##    0                0                0                1                1
##    1                1                1                0                0
##     pred
## true 4.70052406248977 4.71252166536977 4.71790980046024 4.72209390682509
##    0                1                1                1                0
##    1                0                0                0                1
##     pred
## true 4.73700880316426 4.76410732102921 4.79778610227038 4.81008250695993
##    0                1                1                1                0
##    1                0                0                0                1
##     pred
## true 4.9007463572674 4.9354225440078 4.98026113641789 4.98257849795153
##    0               0               1                1                0
##    1               1               0                0                1
##     pred
## true 4.99058151674797 5.03909782004883 5.05515968856742 5.06398513784041
##    0                0                1                1                1
##    1                1                0                0                0
##     pred
## true 5.07132297625174 5.11150096041491 5.13162539397707 5.14658499100586
##    0                1                1                0                1
##    1                0                0                1                0
##     pred
## true 5.15060629752805 5.15318727922966 5.23764488530685 5.24558099788954
##    0                1                0                0                0
##    1                0                1                1                1
##     pred
## true 5.25681437981655 5.26575093401005 5.27316435111095 5.30025944543411
##    0                1                0                1                0
##    1                0                1                0                1
##     pred
## true 5.30614199546506 5.30623792355289 5.31864287016322 5.32873528880407
##    0                1                1                1                1
##    1                0                0                0                0
##     pred
## true 5.36133914125492 5.36626518202354 5.37658177559604 5.39587116671135
##    0                0                1                1                0
##    1                1                0                0                1
##     pred
## true 5.40807309990158 5.4133974524342 5.42606503946116 5.44444778991272
##    0                1               0                1                1
##    1                0               1                0                0
##     pred
## true 5.47809263748457 5.53283777517607 5.57344205362131 5.59414540474643
##    0                1                0                1                1
##    1                0                1                0                0
##     pred
## true 5.60279597771694 5.60766673890283 5.61792790946891 5.62291111574848
##    0                1                0                0                1
##    1                0                1                1                0
##     pred
## true 5.63868931179275 5.68420696315696 5.7039221475028 5.73044150566091
##    0                0                0               0                0
##    1                1                1               1                1
##     pred
## true 5.76317558867266 5.78614593726923 5.79657494333913 5.79962687810292
##    0                1                0                1                1
##    1                0                1                0                0
##     pred
## true 5.79964214434256 5.82074802798559 5.8351134998851 5.86506338567813
##    0                0                0               0                1
##    1                1                1               1                0
##     pred
## true 5.88954836559822 5.89888486230155 5.91080962551167 5.95040333793839
##    0                1                0                0                1
##    1                0                1                1                0
##     pred
## true 5.97602445316841 6.04932851401498 6.05028064792385 6.0777294566982
##    0                0                1                1               0
##    1                1                0                0               1
##     pred
## true 6.08798553479244 6.08953071629037 6.09301723783245 6.10140888729473
##    0                1                1                0                1
##    1                0                0                1                0
##     pred
## true 6.11627533343961 6.12081899178555 6.15811634679665 6.19726300669243
##    0                1                1                1                0
##    1                0                0                0                1
##     pred
## true 6.2000625036784 6.27779873517682 6.36804267448713 6.40246717316439
##    0               0                1                1                1
##    1               1                0                0                0
##     pred
## true 6.42573715431025 6.43143659514715 6.46881773752501 6.48879439813425
##    0                1                0                0                1
##    1                0                1                1                0
##     pred
## true 6.49138307442298 6.50521637742748 6.51583738868465 6.52244310138156
##    0                1                0                1                0
##    1                0                1                0                1
##     pred
## true 6.5489669205748 6.60786123258402 6.61172078979542 6.67788820118984
##    0               1                1                1                1
##    1               0                0                0                0
##     pred
## true 6.69302065541377 6.7000779701524 6.76149445456793 6.79311312419703
##    0                1               0                0                1
##    1                0               1                1                0
##     pred
## true 6.79797311929395 6.84036460762252 6.8441836429887 6.84731265400877
##    0                1                1               1                1
##    1                0                0               0                0
##     pred
## true 6.88086168618282 6.90874319394459 6.92024586406877 6.93806224932303
##    0                1                1                0                1
##    1                0                0                1                0
##     pred
## true 6.96004596223464 6.97236255986025 6.97248957735827 7.03306201902558
##    0                1                1                1                0
##    1                0                0                0                1
##     pred
## true 7.04099149872889 7.05917615500619 7.07618083675732 7.08294060883452
##    0                0                1                1                1
##    1                1                0                0                0
##     pred
## true 7.08913378381511 7.16484531817367 7.21469445397486 7.23869481739928
##    0                1                1                0                0
##    1                0                0                1                1
##     pred
## true 7.29791351930579 7.31860968853687 7.33546047714879 7.35010536072185
##    0                0                0                1                0
##    1                1                1                0                1
##     pred
## true 7.35155846701344 7.43663337977012 7.48773375955751 7.50900453758766
##    0                1                1                0                1
##    1                0                0                1                0
##     pred
## true 7.52959296164443 7.60310993121346 7.62246548441579 7.63131047097375
##    0                0                1                1                0
##    1                1                0                0                1
##     pred
## true 7.72787424792876 7.76061926653018 7.82058400159111 7.85286437218418
##    0                1                1                1                0
##    1                0                0                0                1
##     pred
## true 7.86936759633352 8.01417264399459 8.03614568394949 8.07454650533726
##    0                1                0                1                0
##    1                0                1                0                1
##     pred
## true 8.12328817380001 8.20487425160935 8.26183895823886 8.30382644814779
##    0                0                0                0                1
##    1                1                1                1                0
##     pred
## true 8.34097743044948 8.3494901886337 8.76654380989601 9.04636474755933
##    0                1               1                0                0
##    1                0               0                1                1
##     pred
## true 9.05921324772169 9.11180386749436 9.63743951601317 9.70689466559668
##    0                0                0                1                0
##    1                1                1                0                1
##     pred
## true 9.87213714291682 9.97368353662421 10.0892567081504 10.1641395079099
##    0                0                1                1                0
##    1                1                0                0                1
##     pred
## true 10.4033376505726 10.4291453981899 10.6968767183029 10.9730157932394
##    0                0                0                0                1
##    1                1                1                1                0
##     pred
## true 11.0892742151522 12.2239821419247 13.5071860273496 13.5715662172191
##    0                1                0                1                0
##    1                0                1                0                1

##by processing this code we will be able to develope a prediction of the purpose of a new car that is wihthin the germancredit data. one of the rows seems to have been omitted from the true or false not sure why.

predictions <- predict(svm_model, test_data)

table(true = test_data$Purpose.NewCar, pred = predictions)
##     pred
## true -21.5558765115089 -21.4932117344684 -19.5305243613071 -19.4644627453632
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -18.4744126232214 -17.8795564355202 -15.1798613028474 -14.7060721101112
##    0                 1                 1                 1                 0
##    1                 0                 0                 0                 1
##     pred
## true -14.1198069335766 -13.4512005479879 -12.2399898649998 -12.1704164029903
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -11.691655452723 -11.5673244850583 -11.5389552445955 -11.3266701431818
##    0                1                 1                 1                 1
##    1                0                 0                 0                 0
##     pred
## true -10.2101314695425 -9.6932785393543 -9.40673891770313 -9.33364040719936
##    0                 1                1                 1                 1
##    1                 0                0                 0                 0
##     pred
## true -9.33081564622591 -8.85121549981306 -8.68168340193699 -8.65899116116236
##    0                 1                 0                 1                 1
##    1                 0                 1                 0                 0
##     pred
## true -8.62877048867414 -8.43200893270443 -7.82046209591101 -7.81953056472013
##    0                 0                 1                 1                 1
##    1                 1                 0                 0                 0
##     pred
## true -7.65425813513468 -7.61012105959127 -7.4400719212241 -7.38080531674097
##    0                 1                 1                1                 1
##    1                 0                 0                0                 0
##     pred
## true -7.36100296991537 -7.34649306851099 -7.23843746947716 -6.88586918952535
##    0                 1                 0                 1                 1
##    1                 0                 1                 0                 0
##     pred
## true -6.26004655974577 -6.18827162998388 -6.09064954089592 -5.68884429650972
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -5.10781188624571 -4.33238699602554 -4.09294600727628 -3.87638759928415
##    0                 1                 0                 1                 1
##    1                 0                 1                 0                 0
##     pred
## true -3.85366989615033 -3.59212223755787 -3.39987111406992 -3.36907923164437
##    0                 1                 1                 0                 1
##    1                 0                 0                 1                 0
##     pred
## true -3.23864068406294 -3.17612085806797 -3.1671958895273 -2.93711303117345
##    0                 0                 1                1                 1
##    1                 1                 0                0                 0
##     pred
## true -2.83816706332038 -2.75746394636701 -2.63783355372618 -2.62495135831306
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -2.60991473811338 -2.54201242643068 -2.49236974435518 -2.48847830610941
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true -2.4011463107414 -2.34999691265295 -1.9852247642226 -1.69551377313803
##    0                1                 1                1                 0
##    1                0                 0                0                 1
##     pred
## true -1.59120498913 -1.48870733323167 -1.42197908962737 -1.25963832008312
##    0              1                 0                 1                 1
##    1              0                 1                 0                 0
##     pred
## true -1.2015820102639 -1.14906294586728 -1.07283504995177 -1.01233967336486
##    0                1                 1                 0                 1
##    1                0                 0                 1                 0
##     pred
## true -0.925914901668529 -0.744597795779208 -0.623001455689172
##    0                  0                  0                  1
##    1                  1                  1                  0
##     pred
## true -0.377623557472925 -0.297591249818305 -0.291758216346006
##    0                  1                  1                  1
##    1                  0                  0                  0
##     pred
## true -0.253853545883993 -0.178858909184436 -0.0803447397298616
##    0                  1                  1                   1
##    1                  0                  0                   0
##     pred
## true -0.00225976052353793 0.307362016861935 0.362617264141937 0.391990963941117
##    0                    1                 1                 1                 1
##    1                    0                 0                 0                 0
##     pred
## true 0.458364863520165 0.565579739039441 0.775344756072064 0.796299633210202
##    0                 1                 1                 1                 1
##    1                 0                 0                 0                 0
##     pred
## true 0.829380710249444 0.850852359657784 0.862103570824166 0.898776960199376
##    0                 1                 0                 1                 1
##    1                 0                 1                 0                 0
##     pred
## true 0.899214514171382 0.90552258176138 0.925048079913159 0.946680393641492
##    0                 1                1                 1                 1
##    1                 0                0                 0                 0
##     pred
## true 1.00941681546499 1.11914987174203 1.14390538690021 1.1780904127412
##    0                0                1                1               1
##    1                1                0                0               0
##     pred
## true 1.21133257133295 1.26094111484816 1.43052268457939 1.68122484964659
##    0                0                1                1                1
##    1                1                0                0                0
##     pred
## true 1.70395161268642 1.74869987798264 1.97538517472674 2.01367509794762
##    0                0                1                0                1
##    1                1                0                1                0
##     pred
## true 2.0541607072704 2.08255270925691 2.16074923855593 2.18307979089548
##    0               1                1                0                1
##    1               0                0                1                0
##     pred
## true 2.21840074156751 2.24337764700284 2.25844910984268 2.5283936603122
##    0                1                0                1               1
##    1                0                1                0               0
##     pred
## true 2.64689204712739 2.72320513111879 2.7496879534923 2.81206973699262
##    0                1                0               1                1
##    1                0                1               0                0
##     pred
## true 2.89234077615072 2.96983490103265 3.31097271723082 3.36494835523297
##    0                1                1                0                1
##    1                0                0                1                0
##     pred
## true 3.37091876251032 3.87275322118183 3.88039856088688 3.9219786418729
##    0                1                1                0               1
##    1                0                0                1               0
##     pred
## true 3.94466549028983 3.98727536444892 4.05186942835679 4.05875806567599
##    0                1                1                0                0
##    1                0                0                1                1
##     pred
## true 4.13115068582227 4.27753220928242 4.36387836617758 4.39659747072836
##    0                0                1                0                1
##    1                1                0                1                0
##     pred
## true 4.57094899994661 4.64597938266923 4.71525305939247 4.7477011844643
##    0                1                1                0               1
##    1                0                0                1               0
##     pred
## true 4.80808814299633 4.82534808908929 4.85669146535327 4.87488906142642
##    0                0                0                0                1
##    1                1                1                1                0
##     pred
## true 4.92665556875398 4.96043118705382 5.10815272723665 5.12633609828879
##    0                1                0                0                0
##    1                0                1                1                1
##     pred
## true 5.2458845941477 5.37396184039642 5.40131031592717 5.51612382811834
##    0               1                1                1                1
##    1               0                0                0                0
##     pred
## true 5.51740776990881 5.74951211047699 5.92989775223066 6.17763649356892
##    0                1                1                1                0
##    1                0                0                0                1
##     pred
## true 6.17779836115768 6.31083592829635 6.36938192286869 6.63064021301796
##    0                1                1                1                0
##    1                0                0                0                1
##     pred
## true 6.63233917636206 6.67010988165965 6.67105290723373 6.76066035461952
##    0                0                0                0                1
##    1                1                1                1                0
##     pred
## true 6.82916392070582 6.87091227864255 7.40630517957141 7.49571288434197
##    0                0                1                1                1
##    1                1                0                0                0
##     pred
## true 7.74133897816171 7.78608981018295 7.89230647740295 7.89496468064715
##    0                1                0                0                1
##    1                0                1                1                0
##     pred
## true 8.04884055313994 8.10967281517913 8.4133721092843 8.51824139162307
##    0                0                0               0                0
##    1                1                1               1                1
##     pred
## true 8.5674650302284 9.11060501133432 9.78667264581998 9.81103912425568
##    0               0                0                0                0
##    1               1                1                1                1
##     pred
## true 10.2223528405779 10.5299343248956 11.2844922422559 11.7589976644271
##    0                0                0                1                1
##    1                1                1                0                0
##     pred
## true 12.3220730112993
##    0                0
##    1                1

this specific code tries to predict the amount of people who baught a new vehicle rather than a use one.

colnames(GermanCredit)
##  [1] "Duration"                              
##  [2] "Amount"                                
##  [3] "InstallmentRatePercentage"             
##  [4] "ResidenceDuration"                     
##  [5] "Age"                                   
##  [6] "NumberExistingCredits"                 
##  [7] "NumberPeopleMaintenance"               
##  [8] "Telephone"                             
##  [9] "ForeignWorker"                         
## [10] "Class"                                 
## [11] "CheckingAccountStatus.lt.0"            
## [12] "CheckingAccountStatus.0.to.200"        
## [13] "CheckingAccountStatus.gt.200"          
## [14] "CheckingAccountStatus.none"            
## [15] "CreditHistory.NoCredit.AllPaid"        
## [16] "CreditHistory.ThisBank.AllPaid"        
## [17] "CreditHistory.PaidDuly"                
## [18] "CreditHistory.Delay"                   
## [19] "CreditHistory.Critical"                
## [20] "Purpose.NewCar"                        
## [21] "Purpose.UsedCar"                       
## [22] "Purpose.Furniture.Equipment"           
## [23] "Purpose.Radio.Television"              
## [24] "Purpose.DomesticAppliance"             
## [25] "Purpose.Repairs"                       
## [26] "Purpose.Education"                     
## [27] "Purpose.Vacation"                      
## [28] "Purpose.Retraining"                    
## [29] "Purpose.Business"                      
## [30] "Purpose.Other"                         
## [31] "SavingsAccountBonds.lt.100"            
## [32] "SavingsAccountBonds.100.to.500"        
## [33] "SavingsAccountBonds.500.to.1000"       
## [34] "SavingsAccountBonds.gt.1000"           
## [35] "SavingsAccountBonds.Unknown"           
## [36] "EmploymentDuration.lt.1"               
## [37] "EmploymentDuration.1.to.4"             
## [38] "EmploymentDuration.4.to.7"             
## [39] "EmploymentDuration.gt.7"               
## [40] "EmploymentDuration.Unemployed"         
## [41] "Personal.Male.Divorced.Seperated"      
## [42] "Personal.Female.NotSingle"             
## [43] "Personal.Male.Single"                  
## [44] "Personal.Male.Married.Widowed"         
## [45] "Personal.Female.Single"                
## [46] "OtherDebtorsGuarantors.None"           
## [47] "OtherDebtorsGuarantors.CoApplicant"    
## [48] "OtherDebtorsGuarantors.Guarantor"      
## [49] "Property.RealEstate"                   
## [50] "Property.Insurance"                    
## [51] "Property.CarOther"                     
## [52] "Property.Unknown"                      
## [53] "OtherInstallmentPlans.Bank"            
## [54] "OtherInstallmentPlans.Stores"          
## [55] "OtherInstallmentPlans.None"            
## [56] "Housing.Rent"                          
## [57] "Housing.Own"                           
## [58] "Housing.ForFree"                       
## [59] "Job.UnemployedUnskilled"               
## [60] "Job.UnskilledResident"                 
## [61] "Job.SkilledEmployee"                   
## [62] "Job.Management.SelfEmp.HighlyQualified"
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
GermanCredit$Purpose.NewCar<- as.factor(GermanCredit$Purpose.NewCar)
GermanCredit$CreditHistory.Delay<- as.factor(GermanCredit$CreditHistory.Delay)
GermanCredit$Purpose.UsedCar<- as.factor(GermanCredit$Purpose.UsedCar)

By setting these as factors we will be able to detremine the correlation between having a new car or a used car and if there is any credit historyb delay in any of these two transactions.

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

By using the seed 2023 we will be able yoto have a more accurate reading when trying to determine the index.

germancredit.svm <- svm(Purpose.NewCar ~ ., data = germancredit.train, kernel = 'linear')
## Warning in svm.default(x, y, scale = scale, ..., na.action = na.action):
## Variable(s) 'Purpose.Vacation' and 'Personal.Female.Single' constant. Cannot
## scale data.
predicted_classes_train <- predict(germancredit.svm, germancredit.train)

confusion_matrix_train <- table(true = germancredit.train$Purpose.NewCar, pred = predicted_classes_train)
misclassification_rate_train <- 1 - sum(diag(confusion_matrix_train)) / sum(confusion_matrix_train)

print("Confusion Matrix (Training Set):")
## [1] "Confusion Matrix (Training Set):"
print(confusion_matrix_train)
##     pred
## true   0   1
##    0 609   3
##    1  66 122
print(paste("Misclassification Rate (Training Set):", round(misclassification_rate_train, 4)))
## [1] "Misclassification Rate (Training Set): 0.0863"
predicted_classes_train <- predict(germancredit.svm, newdata = germancredit.train)

Cmatrix_train <- table(true = germancredit.train$Purpose.NewCar, pred = predicted_classes_train)
misclassification_rate_train <- 1 - sum(diag(Cmatrix_train)) / sum(Cmatrix_train)

print("Confusion Matrix (Training Set):")
## [1] "Confusion Matrix (Training Set):"
print(Cmatrix_train)
##     pred
## true   0   1
##    0 609   3
##    1  66 122
print(paste("Misclassification Rate (Training Set):", round(misclassification_rate_train, 4)))
## [1] "Misclassification Rate (Training Set): 0.0863"
1 - sum(diag(Cmatrix_train))/sum(Cmatrix_train)
## [1] 0.08625
pred_credit_test <- predict(germancredit.svm, newdata = germancredit.test)

length_true <- length(germancredit.test$default)
length_pred <- length(pred_credit_test)

print(paste("Length of true values:", length_true))
## [1] "Length of true values: 0"
print(paste("Length of predicted values:", length_pred))
## [1] "Length of predicted values: 200"
str(germancredit.test$default)
##  NULL
str(pred_credit_test)
##  Factor w/ 2 levels "0","1": 1 2 2 1 1 2 1 1 1 1 ...
##  - attr(*, "names")= chr [1:200] "1" "14" "15" "17" ...
print("Unique values in true values:")
## [1] "Unique values in true values:"
print(unique(germancredit.test$default))
## NULL
print("Unique values in predicted values:")
## [1] "Unique values in predicted values:"
print(unique(pred_credit_test))
## [1] 0 1
## Levels: 0 1
colnames(data)
## [1] "y"  "x1" "x2"
# Replace 'actual_variable' with the correct name 'y'
model <- glm(y ~ x1 + x2, data = GermanCredit, family = "binomial")
## Warning: glm.fit: algorithm did not converge
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
# Check the model summary
summary(model)
## 
## Call:
## glm(formula = y ~ x1 + x2, family = "binomial", data = GermanCredit)
## 
## Coefficients:
##              Estimate Std. Error z value Pr(>|z|)
## (Intercept)   -83.692  46644.066  -0.002    0.999
## x1             -6.358  20603.082   0.000    1.000
## x2            149.658  81123.212   0.002    0.999
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 5.1796e+01  on 39  degrees of freedom
## Residual deviance: 5.7692e-09  on 37  degrees of freedom
## AIC: 6
## 
## Number of Fisher Scoring iterations: 25
# Replace 'default' with the actual name of your target variable
target_variable <- "Purpose.NewCar"

credit.svm_asymmetric <- svm(as.factor(get(target_variable)) ~ .,
                              data = germancredit.train, 
                              kernel = 'linear',
                              class.weights = c("0" = 1, "1" = 5))
## Warning in svm.default(x, y, scale = scale, ..., na.action = na.action):
## Variable(s) 'Purpose.Vacation' and 'Personal.Female.Single' constant. Cannot
## scale data.
pred_germancredit_train <- predict(credit.svm_asymmetric, germancredit.train)
table(true = germancredit.train[[target_variable]], pred = pred_germancredit_train)
##     pred
## true   0   1
##    0 609   3
##    1   1 187
length(germancredit.test$default)
## [1] 0
length(pred_credit_test)
## [1] 200
levels(germancredit.train$default)
## NULL
levels(germancredit.test$default)
## NULL
levels(pred_credit_test)
## [1] "0" "1"
str(pred_credit_test)
##  Factor w/ 2 levels "0","1": 1 2 2 1 1 2 1 1 1 1 ...
##  - attr(*, "names")= chr [1:200] "1" "14" "15" "17" ...