Implement predict_proba with test.

Fix tree overload with dataset in nodes only needed in tests
This commit is contained in:
2020-05-14 18:42:17 +02:00
parent e3ae3a3a6c
commit e56b955b92
7 changed files with 154 additions and 281 deletions

11
main.py
View File

@@ -33,14 +33,15 @@ def load_creditcard(n_examples=0):
print("Fraud: {0:.3f}% {1}".format(len(y[y == 1])*100/X.shape[0], len(y[y == 1])))
print("Valid: {0:.3f}% {1}".format(len(y[y == 0])*100/X.shape[0], len(y[y == 0])))
return X, y
#X, y = load_creditcard(-5000)
#X, y = load_creditcard(0)
X, y = load_creditcard(-5000)
#X, y = load_creditcard()
clf = Stree(C=.01, max_iter=100, random_state=random_state)
clf.fit(X, y)
print(clf)
clf.show_tree()
clf.save_sub_datasets()
print(f"Predicting {y[0]} we have {clf.predict(X[0, :].reshape(-1, X.shape[1]))}")
#clf.show_tree()
#clf.save_sub_datasets()
yp = clf.predict_proba(X[0, :].reshape(-1, X.shape[1]))
print(f"Predicting {y[0]} we have {yp[0, 0]} with {yp[0, 1]} of belief")
print(f"Classifier's accuracy: {clf.score(X, y, print_out=False):.4f}")
clf.show_tree(only_leaves=True)