Skip to main content

KDE Classifier with feature selection and Naive Bayes

Project description

Explainable Class–Specific Naive–Bayes Classifier

Explicable Naive Bayes (XNB) classifier includes two important features:

  1. The probability is calculated by means of Kernel Density Estimation (KDE).

  2. The probability for each class does not use all variables, but only those that are relevant for each specific class.

From the point of view of the classification performance, the XNB classifier is comparable to NB classifier. However, the XNB classifier provides the subsets of relevant variables for each class, which contributes considerably to explaining how the predictive model is performing. In addition, the subsets of variables generated for each class are usually different and with remarkably small cardinality.

Example of use:

from xnb import XNB
from xnb.enum import BWFunctionName, Kernel, Algorithm
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import pandas as pd

''' 1. Read the dataset. It is important that the dataset is a pandas DataFrame object with named columns. This way, we can obtain the dictionary of important variables for each class.'''
df = pd.read_csv("path_to_data/iris.csv")
x, y = df.iloc[:, 0:-1], df.iloc[:,-1]
x_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.20, random_state=0)

''' 2. By calling the fit() function, we prepare the object to be able to make the prediction later. '''
xnb = XNB(
  show_progress_bar = True # optional
)
xnb.fit(
  x_train,
  y_train,
  bw_function = BWFunctionName.HSILVERMAN, # optional
  kernel = Kernel.GAUSSIAN, # optional
  algorithm = Algorithm.AUTO, # optional
  n_sample = 50 # optional
)

''' 3. When the fit() function finishes, we can now access the feature selection dictionary it has calculated. '''
feature_selection = xnb.feature_selection_dict

''' 4. We predict the values of "y_test" using implicitly the calculated dictionary. '''
y_pred = xnb.predict(X_test)

# Output
print(feature_selection)
print(accuracy_score(y_test, y_pred))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xnb-0.2.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

xnb-0.2.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file xnb-0.2.1.tar.gz.

File metadata

  • Download URL: xnb-0.2.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for xnb-0.2.1.tar.gz
Algorithm Hash digest
SHA256 353d97afcbda55acf802c87196971dc3dbfdfa2f92952e61967b11b6bd06a460
MD5 b8b9b0434e9cb1b63d496cd9fd612d5e
BLAKE2b-256 722fea00884d983e4dc3e2e6f59e237f8f7604e8ce0dd434a5f593c906ce29f6

See more details on using hashes here.

File details

Details for the file xnb-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: xnb-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for xnb-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f5ac7aea5e10ca0947bc45fb3c8617b816d4a0c61d25359f687b2bab53821eb3
MD5 23483f38d9e37325682e5ab770991cf1
BLAKE2b-256 e9fcdacded21fc30f0708db424d4452270470e5df55b5594d8f724854ae735df

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page