hemanta
hemanta

Reputation: 1510

Accuracy in naive bayes classification is 100%

I have a classification problem for which I want to do classification for class A, B, and C. I try to use naive bayes classifier and the accuracy is 100%, which I really doubt is not true. I have small dataset around 350, among that class A is 140, class B is 140 and rest are class C. Here is the code I used. Can anyone please provide me some suggestions on this?

import sklearn
from sklearn.metrics import accuracy_score
X = feature_data_frame.values
y = label_data
import sklearn.preprocessing as preprocessing
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB, MultinomialNB
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=.10)
gnb = GaussianNB()
y_pred = gnb.fit(x_train, y_train).predict(x_test)
accuracy = accuracy_score(y_test, y_pred)

Thanks in advance.

Upvotes: 0

Views: 2306

Answers (1)

Farhan Ar Rafi
Farhan Ar Rafi

Reputation: 148

A few days earlier I also faced the same issue while classifying stock data into risky and non risky classes using Gaussian Naive Bayes Classifier.

There might be two issues in your code:

  1. You need to scale your data (X_train and X_test) using StandardScaler or some other scaler
  2. Your training data might have some outliers that are messing up with your model accuracy.

Let us know how it goes!

Upvotes: 0

Related Questions