-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebuggingEC.java
More file actions
110 lines (82 loc) · 5.16 KB
/
Copy pathDebuggingEC.java
File metadata and controls
110 lines (82 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package debuggingec;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
/**
*
* @author Kevin Jang
*/
public class DebuggingEC {
public static void main(String[] args) {
//initialize variables
Scanner fileRead = null;
ArrayList<BankObject> bankObjectListTraining = new ArrayList<>();
ArrayList<BankObject> bankObjectListTesting = new ArrayList<>();
ArrayList<List> dataToSend = new ArrayList<>();
//check to make sure we can open file
try {
fileRead = new Scanner(new File("bank-full.csv"));
} catch (FileNotFoundException e) {
System.out.println("File Location unknown.");
}
//skip first line since it is nothing but headers
String line = fileRead.nextLine();
while (fileRead.hasNextLine()) {
//initliaze temporary variables
line = fileRead.nextLine();
List<String> tempAccount = new ArrayList<>();
//split each line into a String array of values
String[] lineSplit = line.split(";");
//read in lineSplit into an arraylist object
ArrayList<String> accountList = new ArrayList<String>(Arrays.asList(lineSplit));
//for each item in accountList, we use regex to remove double quotes, then add into tempAccount. This creates an ArrayList object that holds all the relevant information of the first 8 columns.
for(int i = 0; i < 8; i++){
String temp = accountList.get(i).toString().toLowerCase();
temp = temp.replaceAll("^\"|\"$", "");
tempAccount.add(temp);
}
//add the last column of the relevant data from our lineSplit String Array
String lastElement = accountList.get(accountList.size()-1);
lastElement = lastElement.replaceAll("^\"|\"$", "");
tempAccount.add(lastElement);
//rather than send each information to create a bank object, we add to an ArrayList object called dataToSend to send all relevant data at once.
dataToSend.add(tempAccount);
}
//close fileRead since we are done with its usage at this time. We have all relevant data necessary.
fileRead.close(); // Moved outside of while loop due to scanner closing too early
//for each item in dataToSend, we create a bankObject with its information. Add this to a list
for (List account : dataToSend){
BankObject tempBankObject = new BankObject(account);
bankObjectListTraining.add(tempBankObject);
}
//select a random assortment for the training set and testing set.
Random randomSelector = new Random();
int randomSize = randomSelector.nextInt(6000 - 4000 + 1) + 4000;
for(int k = 0; k < randomSize; k++){ // Instead of randomSelector, use randomSize
int randomIndex = randomSelector.nextInt(bankObjectListTraining.size());
bankObjectListTraining.remove(randomIndex);
BankObject tempHolder = bankObjectListTraining.get(randomIndex);
bankObjectListTraining.remove(randomIndex);
bankObjectListTesting.add(tempHolder);
}
//create DecisionTreeTools Object to make things easier to access and read.
DecisionTreeTools treeTools = new DecisionTreeTools(bankObjectListTesting, bankObjectListTraining);
//print results.
System.out.println("The size of the training set is: " + treeTools.getTrainingSize());
System.out.println("The size of the testing set is: " + treeTools.getTestingSize());
System.out.println("The average age in the training set is: " + treeTools.getAvgAgeTraining());
System.out.println("The average age in the testing set is: " + treeTools.getAvgAgeTesting());
System.out.println("The average balance in the training set is: " + treeTools.getAvgBalanceTraining());
System.out.println("The average balance in the testing set is: " + treeTools.getAvgBalanceTesting());
System.out.println("The percentage of defaulted applicants in the training set is: " + treeTools.getDefaultedEntropyTraining());
System.out.println("The percentage of defaulted applicants in the testing set is: " + treeTools.getDefaultedEntropyTesting());
System.out.println("The percentage of applicants with housing in the training set is: " + treeTools.getHousingEntropyTraining());
System.out.println("The percentage of applicants with housing in the testing set is: " + treeTools.getHousingEntropyTesting());
System.out.println("The percentage of applicants with loans in the training set is: " + treeTools.getLoanEntropyTraining());
System.out.println("The percentage of applicants with loans in the testing set is: " + treeTools.getLoanEntropyTesting());
}
}