BayesNets
contains various implementations of the Naive Bayes through the perspective of Naive Bayes as a special version of a Bayesian Network.
-
Classic Naive Bayes with Nonparametric Density Estimation
-
Selecive Naive Bayes algorithm (k-fold CV)
-
Tree Augmented Naive Bayes (treenb: discrete data and kdetree: continuous data)
-
Forest Augmented Naive Bayes (treenb: discrete data and kdetree: continuous data). An "optimized" version of TAN for ranking.
-
Hierarchical Naive Bayes (in development)
import numpy as np
import pandas as pd
import NaiveBayesNets as nbn
df = pd.read_csv("data/Pima.tr.csv")
class_col_name = 'type'
nbmodel = nbn.NaiveBayes(df, class_col_name)
preds = nbmodel.Predict(df) ## prediction probs
preds[class_col_name] = preds.idxmax(axis = 1) ## to get class predictions
preds.head()
accuracy = np.mean(preds[class_col_name].values == preds[class_col_name])
print(accuracy)
-
Numpy
-
Scipy
-
Pandas
-
Itertools
-
Matplotlib
-
Networkx
See TAN for an example of a Tree Augmented Naive Bayes.