Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if y_pred == None:
y_pred = node['LABEL']
if y_pred == y:
correct += 1
return 1.0 * correct / len(Y)
if __name__ == '__main__':
train_path = 'data/2_newsgroups.train'
test_path = 'data/2_newsgroups.test'
X_train, Y_train = read_sparse_data(open(train_path))
X_test, Y_test = read_sparse_data(open(test_path))
clf = ID3()
clf.train(X_train, Y_train)
acc_train = clf.test(X_train, Y_train)
acc_test = clf.test(X_test, Y_test)
print >> sys.stderr, 'Training accuracy for ID3 : %f%%' % (100 * acc_train)
print >> sys.stderr, 'Test accuracy for ID3 : %f%%' % (100 * acc_test)
clf.dump_model(open('data/dt.model', 'w'), open('data/dt.rule_set', 'w'))