r:neural_network
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
r:neural_network [2016/12/14 08:37] – [E.G. 3] hkimscil | r:neural_network [2016/12/14 09:02] (current) – [E.G 5] hkimscil | ||
---|---|---|---|
Line 528: | Line 528: | ||
</ | </ | ||
- | ## test the resulting | + | __test |
< | < | ||
Line 536: | Line 536: | ||
results <- data.frame(actual = testset$default10yr, | results <- data.frame(actual = testset$default10yr, | ||
results[100: | results[100: | ||
- | ## | ||
- | ## 900 0 0.0000000000000000000000000015964854322398 | ||
- | ## 901 0 0.0000000000000000000000000065162871249459 | ||
- | ## 902 0 0.0000000000164043993271687692878796349660 | ||
- | ## 903 1 0.9999999999219191249011373656685464084148 | ||
- | ## 904 0 0.0000000000000000013810778585990359033486 | ||
- | ## 905 0 0.0000000000000000539636283549265018946381 | ||
- | ## 906 0 0.0000000000000000000234592312583958126923 | ||
- | ## 907 1 0.9581419934268182725389806364546529948711 | ||
- | ## 908 0 0.2499229633059911748205195181071758270264 | ||
- | ## 909 0 0.0000000000000007044361454974853363648901 | ||
- | ## 910 0 0.0006082559674722616289282983714770125516 | ||
- | ## 911 1 0.9999999878713862200285689141310285776854 | ||
- | ## 912 0 0.0000000000000000000000000015562211243506 | ||
- | ## 913 1 0.9999999993455563895849991240538656711578 | ||
- | ## 914 0 0.0000000000000000000000000000003082538282 | ||
- | ## 915 0 0.0000000019359618836434052080615331181690 | ||
results$prediction <- round(results$prediction) | results$prediction <- round(results$prediction) | ||
results[100: | results[100: | ||
- | ## | + | |
- | ## 900 0 0 | + | pred.table <- table(testset$default10yr, |
- | ## 901 0 0 | + | pred.table |
- | ## 902 0 0 | + | |
- | ## 903 1 1 | + | library(plyr) |
- | ## 904 0 0 | + | count(testset, |
- | ## 905 0 0 | + | |
- | ## 906 0 0 | + | |
- | ## 907 1 1 | + | |
- | ## 908 0 0 | + | |
- | ## 909 0 0 | + | |
- | ## 910 0 0 | + | |
- | ## 911 1 1 | + | |
- | ## 912 0 0 | + | |
- | ## 913 1 1 | + | |
- | ## 914 0 0 | + | |
- | ## 915 0 0 | + | |
- | + | ||
</ | </ | ||
+ | |||
+ | with outputs | ||
+ | < | ||
+ | > library(" | ||
+ | > | ||
+ | > dataset <- read.csv(" | ||
+ | > head(dataset) | ||
+ | clientid | ||
+ | 1 1 66155.92510 59.01701507 8106.53213129 0.1225367511623 | ||
+ | 2 2 34415.15397 48.11715310 6564.74501768 0.1907515806612 | ||
+ | 3 3 57317.17006 63.10804949 8020.95329639 0.1399397996720 | ||
+ | 4 4 42709.53420 45.75197235 6103.64226014 0.1429105321411 | ||
+ | 5 5 66952.68885 18.58433593 8770.09923520 0.1309894999955 | ||
+ | 6 6 24904.06414 57.47160710 | ||
+ | default10yr | ||
+ | 1 0 | ||
+ | 2 0 | ||
+ | 3 0 | ||
+ | 4 0 | ||
+ | 5 1 | ||
+ | 6 0 | ||
+ | > | ||
+ | > # extract a set to train the NN | ||
+ | > trainset <- dataset[1: | ||
+ | > | ||
+ | > # select the test set | ||
+ | > testset <- dataset[801: | ||
+ | > | ||
+ | > ## build the neural network (NN) | ||
+ | > creditnet <- neuralnet(default10yr ~ LTI + age, trainset, hidden = 4, lifesign = " | ||
+ | + linear.output = FALSE, threshold = 0.1) | ||
+ | hidden: 4 thresh: 0.1 rep: 1/1 steps: | ||
+ | > | ||
+ | > ## plot the NN | ||
+ | > plot(creditnet, | ||
+ | > | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | > | ||
+ | > creditnet.results <- compute(creditnet, | ||
+ | > head(temp_test) | ||
+ | LTI age | ||
+ | 801 0.02306808811 25.90644520 | ||
+ | 802 0.13729704954 40.77430558 | ||
+ | 803 0.10456984914 32.47350580 | ||
+ | 804 0.15985046411 53.22813215 | ||
+ | 805 0.11161429579 46.47915325 | ||
+ | 806 0.11489364221 47.12736998 | ||
+ | > | ||
+ | > results <- data.frame(actual = testset$default10yr, | ||
+ | > results[100: | ||
+ | actual | ||
+ | 900 0 0.0000000000000000000000000015964854322398 | ||
+ | 901 0 0.0000000000000000000000000065162871249459 | ||
+ | 902 0 0.0000000000164043993271687692878796349660 | ||
+ | 903 1 0.9999999999219191249011373656685464084148 | ||
+ | 904 0 0.0000000000000000013810778585990655628959 | ||
+ | 905 0 0.0000000000000000539636283549268839978413 | ||
+ | 906 0 0.0000000000000000000234592312583964807452 | ||
+ | 907 1 0.9581419934268182725389806364546529948711 | ||
+ | 908 0 0.2499229633059938393557786184828728437424 | ||
+ | 909 0 0.0000000000000007044361454974903653282470 | ||
+ | 910 0 0.0006082559674722681341413332845036165963 | ||
+ | 911 1 0.9999999878713862200285689141310285776854 | ||
+ | 912 0 0.0000000000000000000000000015562211243506 | ||
+ | 913 1 0.9999999993455563895849991240538656711578 | ||
+ | 914 0 0.0000000000000000000000000000003082538282 | ||
+ | 915 0 0.0000000019359618836434052080615331181690 | ||
+ | > | ||
+ | > results$prediction <- round(results$prediction) | ||
+ | > results[100: | ||
+ | actual prediction | ||
+ | 900 0 0 | ||
+ | 901 0 0 | ||
+ | 902 0 0 | ||
+ | 903 1 1 | ||
+ | 904 0 0 | ||
+ | 905 0 0 | ||
+ | 906 0 0 | ||
+ | 907 1 1 | ||
+ | 908 0 0 | ||
+ | 909 0 0 | ||
+ | 910 0 0 | ||
+ | 911 1 1 | ||
+ | 912 0 0 | ||
+ | 913 1 1 | ||
+ | 914 0 0 | ||
+ | 915 0 0 | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | > pred.table | ||
+ | |||
+ | | ||
+ | 0 1035 1 | ||
+ | 1 3 161 | ||
+ | > | ||
+ | |||
+ | > library(plyr) | ||
+ | > count(testset, | ||
+ | default10yr freq | ||
+ | 1 0 1036 | ||
+ | 2 | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== E.G 5 ====== | ||
r/neural_network.1481674070.txt.gz · Last modified: 2016/12/14 08:37 by hkimscil