'Table from results of sknn function (klaR package) won't output
I have a data set with 100 observations of 6 variables that I'm trying to run the sknn function on and then output a table of the results. I have updated the response variable to a factor to use as row and column headers in the table, and checked the data types of all other variables to make sure they are compatible (int and num). For some reason, no matter what I try, R freezes trying to pull the table of results and eventually crashes.
Here is the code I'm using:
loans_k$action_taken <- as.factor(loans_k$action_taken)
loans_k.knn <- sknn(loans_k$action_taken ~ ., data = loans_k, kn = 6)
loans_knntab <- table(loans_k$action_taken, predict(loans_k.knn)$class)
The data I'm using is:
> dput(loans_k)
structure(list(action_taken = structure(c(1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("0",
"1"), class = "factor"), loan_type = c(1L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), loan_purpose = c(2L,
1L, 4L, 1L, 31L, 31L, 32L, 1L, 1L, 2L, 1L, 31L, 1L, 1L, 1L, 1L,
1L, 32L, 1L, 1L, 31L, 2L, 31L, 4L, 32L, 32L, 1L, 32L, 2L, 31L,
1L, 32L, 32L, 1L, 5L, 2L, 32L, 31L, 1L, 1L, 31L, 32L, 31L, 32L,
32L, 31L, 1L, 1L, 32L, 31L, 31L, 1L, 31L, 1L, 1L, 1L, 31L, 32L,
4L, 4L, 4L, 4L, 1L, 31L, 31L, 31L, 32L, 1L, 1L, 1L, 31L, 4L,
2L, 31L, 2L, 4L, 31L, 1L, 32L, 1L, 31L, 32L, 1L, 31L, 1L, 31L,
1L, 2L, 1L, 31L, 31L, 4L, 31L, 1L, 2L, 31L, 32L, 32L, 31L, 2L
), loan_to_value_ratio = c(63.2, 102.23, 55.98, 95, 75, 59.719,
24.038, 56.111, 98.02, 50, 80, 73.642, 96.5, 75, 73.723, 75,
63.141, 78.328, 66.32, 95, 61.667, 80, 81.944, 80, 58.685, 75.955,
85, 80, 50.144, 84.848, 80, 55.671, 60, 100, 64, 87.511, 48.541,
73.735, 102.16, 80, 61.62, 78.947, 44.64, 55.556, 26.846, 40.425,
102.391, 47.71, 51.333, 89.82, 78.949, 36.32, 55.441, 96.5, 95,
28.704, 74.199, 67.33, 77.84, 97.326, 26.75, 102, 80, 47.193,
76.27, 22.096, 72.759, 75, 97, 95, 67.942, 35.86, 84.04, 80,
92.25, 83.06, 85, 53.58, 75, 80, 54.415, 64.947, 100, 82, 80,
91.34, 95, 82.15, 100.514, 57.896, 71.42, 100, 59.905, 93.103,
79.91, 79.72, 60, 43.9, 79.772, 73.58), loan_term = c(60L, 360L,
240L, 360L, 348L, 360L, 180L, 360L, 360L, 60L, 360L, 312L, 360L,
360L, 360L, 360L, 240L, 360L, 180L, 360L, 360L, 360L, 360L, 240L,
180L, 360L, 360L, 360L, 120L, 360L, 360L, 360L, 360L, 360L, 240L,
240L, 360L, 360L, 360L, 360L, 240L, 360L, 60L, 180L, 120L, 180L,
360L, 360L, 120L, 360L, 360L, 360L, 360L, 360L, 360L, 180L, 360L,
360L, 360L, 60L, 360L, 360L, 360L, 180L, 360L, 120L, 360L, 360L,
360L, 360L, 180L, 120L, 360L, 360L, 60L, 240L, 360L, 240L, 360L,
360L, 360L, 360L, 360L, 360L, 360L, 360L, 360L, 120L, 360L, 360L,
360L, 360L, 360L, 360L, 240L, 360L, 240L, 240L, 360L, 361L),
debt_to_income_ratio = c(30L, 50L, 36L, 38L, 38L, 48L, 20L,
49L, 36L, 20L, 39L, 44L, 42L, 30L, 20L, 30L, 44L, 50L, 44L,
36L, 30L, 30L, 39L, 38L, 46L, 36L, 30L, 36L, 30L, 36L, 36L,
49L, 20L, 36L, 36L, 60L, 41L, 30L, 36L, 41L, 30L, 41L, 20L,
38L, 60L, 20L, 44L, 42L, 36L, 20L, 41L, 30L, 30L, 45L, 36L,
42L, 42L, 39L, 36L, 50L, 36L, 46L, 36L, 36L, 50L, 30L, 43L,
36L, 37L, 50L, 30L, 20L, 30L, 42L, 36L, 60L, 36L, 30L, 36L,
20L, 49L, 30L, 40L, 30L, 47L, 49L, 43L, 30L, 30L, 30L, 36L,
41L, 36L, 37L, 30L, 20L, 42L, 38L, 30L, 36L)), row.names = c(NA,
100L), class = "data.frame")
How can I get R to output the desired table?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
