invalid 'type' (character) of argument

Whcrs

It is the error message on the topic. I am getting this error when I try to run naive.bayes classifier. Here is the summary of my train data:

'data.frame':   7269 obs. of  193 variables:
 $ pid       : int  2 4 5 7 10 11 14 18 25 31 ...
 $ acquir    : int  0 0 0 0 1 1 0 0 0 0 ...
 $ addit     : int  0 0 0 0 2 2 0 0 0 0 ...
 $ agre      : int  0 0 0 0 0 0 0 0 0 0 ...
 $ agreement : int  0 0 0 0 0 0 0 0 0 0 ...
 $ also      : int  1 0 0 0 2 2 0 0 0 0 ...
 $ american  : int  0 0 0 0 0 0 0 0 0 0 ...
 $ announc   : int  0 0 0 0 0 0 0 0 0 0 ...
 $ annual    : int  0 0 0 0 0 0 0 0 2 0 ...
 $ approv    : int  0 3 0 0 0 0 0 0 0 0 ...
 $ april     : int  0 0 0 0 0 0 0 0 1 0 ...
 $ bank      : int  0 7 0 0 0 0 0 0 0 0 ...
 $ base      : int  0 0 0 0 0 0 0 0 0 0 ...
 .
 .
 $... all of them are integer, except the class column
 .
 .
 $ class     : Factor w/ 10 levels "acq","corn","crude",..: 1 1 4 4 9 1 4 3 1 4 ...

And this is the naive.bayes() line:

model <- naiveBayes(as.factor(class) ~ ., data = as.matrix(train), laplace = 3)

Can anyone tell me why it is happening?:

Error in sum(x) : invalid 'type' (character) of argument
jogo

Eventually your data is converted to character because of as.matrix(train). Try 

model <- naiveBayes(class ~ ., data=train, laplace = 3)

or eventually 

model <- naiveBayes(train$class ~ ., data=train[, -c("class")], laplace = 3)

The second variant is more or less the same as the first variant. The . in the RHS of the formula is expanded to 'all other variables'; so it excludes the column class mentioned on the LHS. (More information is in the documentation of formula)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

error: invalid type argument of unary '*'

From Dev

invalid type argument of ‘->’

From Dev

error: invalid type argument of 'unary *' (have 'int')|

From Dev

error: invalid type argument of ‘->’ (have ‘int’)

From Dev

error creating chisq.test() in R - invalid 'type' (character) of argument

From Dev

invalid type argument of '->' C

From Dev

invalid type argument of ‘->’ (have ‘color’)

From Dev

UPDATE error: "Argument data type text is invalid for argument 1 of REPLACE"

From Dev

Argument type varchar invalid

From Dev

invalid type argument of '->'

From Dev

"invalid use of incomplete type" for const function pointer type as template argument

From Dev

lua - invalid argument type

From Dev

Getting "invalid 'type' (character) of argument" error with aggregate()

From Dev

SQL Argument data type int is invalid for argument 1 of charindex function

From Dev

Dart: "Invalid argument(s): Illegal character in path" when building on Windows

From Dev

Tensorflow TypeError: Fetch argument None has invalid type <type 'NoneType'>?

From Dev

R: Error says invalid 'type' (character) of argument

From Dev

Invalid macro expansion argument character

From Dev

error: invalid type argument of unary '*'

From Dev

#define and invalid type argument of unary ‘*’ (have ‘double’)

From Dev

.: createDirectory: invalid argument (Invalid argument)

From Dev

Using Table to Group: invalid 'type' (character) of argument

From Dev

"invalid use of incomplete type" for const function pointer type as template argument

From Dev

Invalid type argument of '*' (have 'double') C

From Dev

"Argument data type ntext is invalid for argument 1 of len function" error

From Dev

Missing or invalid type argument for pointer action - Selenium

From Dev

invalid 'envir' argument of type 'closure' in R shiny

From Dev

purrr with linear model in R: invalid 'envir' argument of type 'character'

From Dev

SQL Code = -420 Invalid character found in a character string argument of the function "decfloat"

Related Related

  1. 1

    error: invalid type argument of unary '*'

  2. 2

    invalid type argument of ‘->’

  3. 3

    error: invalid type argument of 'unary *' (have 'int')|

  4. 4

    error: invalid type argument of ‘->’ (have ‘int’)

  5. 5

    error creating chisq.test() in R - invalid 'type' (character) of argument

  6. 6

    invalid type argument of '->' C

  7. 7

    invalid type argument of ‘->’ (have ‘color’)

  8. 8

    UPDATE error: "Argument data type text is invalid for argument 1 of REPLACE"

  9. 9

    Argument type varchar invalid

  10. 10

    invalid type argument of '->'

  11. 11

    "invalid use of incomplete type" for const function pointer type as template argument

  12. 12

    lua - invalid argument type

  13. 13

    Getting "invalid 'type' (character) of argument" error with aggregate()

  14. 14

    SQL Argument data type int is invalid for argument 1 of charindex function

  15. 15

    Dart: "Invalid argument(s): Illegal character in path" when building on Windows

  16. 16

    Tensorflow TypeError: Fetch argument None has invalid type <type 'NoneType'>?

  17. 17

    R: Error says invalid 'type' (character) of argument

  18. 18

    Invalid macro expansion argument character

  19. 19

    error: invalid type argument of unary '*'

  20. 20

    #define and invalid type argument of unary ‘*’ (have ‘double’)

  21. 21

    .: createDirectory: invalid argument (Invalid argument)

  22. 22

    Using Table to Group: invalid 'type' (character) of argument

  23. 23

    "invalid use of incomplete type" for const function pointer type as template argument

  24. 24

    Invalid type argument of '*' (have 'double') C

  25. 25

    "Argument data type ntext is invalid for argument 1 of len function" error

  26. 26

    Missing or invalid type argument for pointer action - Selenium

  27. 27

    invalid 'envir' argument of type 'closure' in R shiny

  28. 28

    purrr with linear model in R: invalid 'envir' argument of type 'character'

  29. 29

    SQL Code = -420 Invalid character found in a character string argument of the function "decfloat"

HotTag

Archive