Svm missing value that requires TRUE / FALSE in R

I am trying to implement binary svm. I have the following error message:

Error in if (any(co)) { : missing value where TRUE/FALSE needed

For the following code:

library(e1071)
dataset <- read.csv("C:/Users/Backup/Desktop/pos.csv")
# Subset the dataset dataset to only 2 labels and 2 features
dataset.part = subset(dataset, label != 1)
dataset.part$label = factor(dataset.part$label)


# Fit svm model
fit = svm(label ~ ., data=dataset.part, type='C-classification',   kernel='linear')

I get an error in this line of code:

# Fit svm model
fit = svm(label ~ ., data=dataset.part, type='C-classification', kernel='linear')

I am new to R and I do not know how to solve this. Can anyone help me?

+4
source share
1 answer

I ran into the same problem and was able to narrow it to an infinite value in one of my lines. My suggestion was to pre-process the data first. In my case, I can afford to just omit na and endless values

# First cast Inf to NA
is.na(df) <- sapply(df, is.infinite)
# Now just omit NA
na.omit(df)

@MrFlick . , , , , .

+2

Source: https://habr.com/ru/post/1583824/


All Articles