-
Notifications
You must be signed in to change notification settings - Fork 0
/
cn2_census.R
29 lines (20 loc) · 972 Bytes
/
cn2_census.R
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
# Run pre processing
source('pre_processing_census_data_for_cn2.R')
# Load libraries
library(RoughSets)
library(caret)
# Create the traning decision table
decision_table_training = SF.asDecisionTable(dataset = training_base, decision.attr = 15)
# Create the test decision table
decision_table_test = SF.asDecisionTable(dataset = test_base, decision.attr = 15)
# Generate interval labels for numeric columns
intervals = D.discretization.RST(decision_table_training, nOfIntervals = 4)
decision_table_training = SF.applyDecTable(decision_table_training, intervals)
decision_table_test = SF.applyDecTable(decision_table_test, intervals)
# Run the CN2 classificator
classificator = RI.CN2Rules.RST(decision_table_training, K = 1)
census_predict = predict(classificator, newdata = decision_table_test[-15])
#Create the confusion matrix
confusion_matrix = table(decision_table_test[, 15], census_predict[, 1])
#Analyze confusion matrix
confusionMatrix(confusion_matrix)