Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8694177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:43:28+00:00 2026-06-13T00:43:28+00:00

I use naiveBayes (e1071 http://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Classification/Na%C3%AFve_Bayes ) for classifying my data set (Classification class: class

  • 0

I use naiveBayes (e1071 http://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Classification/Na%C3%AFve_Bayes) for classifying my data set (Classification class: “class” 0/1). Here is what I do:

library(e1071)
arrhythmia <- read.csv(file="/home/.../arrhythmia.csv", head=TRUE, sep=",")

#devide into training and test data 70:30
trainingIndex <- createDataPartition(arrhythmia$class, p=.7, list=F)
arrhythmia.training <- arrhythmia[trainingIndex,]
arrhythmia.testing <- arrhythmia[-trainingIndex,]

nb.classifier <- naiveBayes(class ~ ., data = arrhythmia.training)
predict(nb.classifier,arrhythmia.testing[,-260])

The classifier does not work, here is what I get:

> predict(nb.classifier,arrhythmia.testing[,-260])
factor(0)
Levels: 

> str(arrhythmia.training)
'data.frame':   293 obs. of  260 variables:
 $ age                         : int  75 55 13 40 44 50 62 54 30 46 ...
 $ sex                         : int  0 0 0 1 0 1 0 1 0 1 ...
 $ height                      : int  190 175 169 160 168 167 170 172 170 158 ...
 $ weight                      : int  80 94 51 52 56 67 72 58 73 58 ...
 $ QRSduration                 : int  91 100 100 77 84 89 102 78 91 70 ...
 $ PRinterval                  : int  193 202 167 129 118 130 135 155 180 120 ...
 # and so on (260 attributes)

> str(arrhythmia.training[260])
'data.frame':   293 obs. of  1 variable:
 $ class: int  1 0 1 0 0 1 1 1 1 0 ...


> nb.classifier$levels
NULL

I tried to use the included the data set (iris) and everything works fine.
What’s wrong with my approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:43:30+00:00Added an answer on June 13, 2026 at 12:43 am

    Make sure that you treat class variable as factor; i.e.

    nb.classifier <- naiveBayes(as.factor(class) ~ ., data = arrhythmia.training)
    

    By the way, you don’t need to exclude class variable from predict call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

use strict; use warnings; use Data::Dumper; my %h; my $undef = undef; $h{''}='test2'; $h{$undef}
use LWP::UserAgent; use Data::Dumper; my $ua = new LWP::UserAgent; $ua->agent(AgentName/0.1 . $ua->agent); my $req
USE CASE Search Category to find places near Your address (see form screenshot: http://o7.no/KYCj6v
use messagepack on android, the can serialize/deserialize a class, but not absolutely right .
Use of java.net.URLConnection is asked about pretty often here, and the Oracle tutorial is
use 5.010; use strict; use warnings; use JSON::XS; use YAML::XS; my %data = ();
USE master GO DECLARE @DbName nvarchar(MAX) SET @DbName = N'DataBase' ALTER DATABASE @DbName SET
Use http://jobs.sitesixteen.com/ for reference. I'm using YQL for the city, state auto-complete. IF you
use ThreadPool.QueueUserWorkItem (WaitCallback, Object) to start a thread with my target method and data.
Use paperclip for my images. Models: class Country < ActiveRecord::Base has_many :regions has_many :assets,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.