probability and classification in svm function of e1071 package in R

Viewed 2974

I'm using SVM in e1071 package for binary classification. I'm using both the probability attribute, and the SVM predict classification to compare the results. What I'm puzzled by is that the predicted classification (0 or 1) of the predict function doesn't seem congruous with the actual probabilities listed in the attribute. For some very high probabilities for level 1, the SVM classification is level 0, and for some low probabilities for level 1, the SVM classification is level 1.

here's a sample code and results

svm_model <- svm(as.factor(CHURNED) ~ .
                  , scale = FALSE
                  , data = train
                  , cost = 1
                  , gamma = 0.1
                  , kernel = "radial"
                  , probability = TRUE

    )
 test$Pred_Class <- predict(svm_model, test, probability = TRUE)
 test$Pred_Prob <- attr(test$Pred_Class, "probabilities")[,1]

Here is the results: (rows have been placed differently to see various examples)

CHURNED: is response variable that is being predicted

Pred_class: is the predicted class by SVM

Pred_Prob: is the predicted probability, based on which SVM makes classification?

CHURNED Pred_Class  Pred_Prob
    1   0   0.03968526    # --> makes sense
    1   0   0.03968526
    1   0   0.07033222
    1   0   0.11711195
    1   0   0.12477983
    1   0   0.12827296
    1   0   0.12829345
    1   0   0.12829345
    1   0   0.12829345
    1   0   0.12829444
    1   0   0.12829927
    1   0   0.12829927
    1   0   0.12831169
    1   0   0.12831169
    1   0   0.12831428
    1   1   0.13053475   # --> doesn't make sense. Prob is less than 0.5
    1   1   0.13053475
    1   1   0.13053475
    1   1   0.1305348
    1   1   0.1305348
    1   1   0.1305348
    1   1   0.1690807
    1   1   0.2206993
    1   1   0.2321171
    0   0   0.998289      # --> doesn't make sense. Prob is almost 1!
    0   0   0.9982887
    0   0   0.993133
    0   0   0.9898889
    1   0   0.9849951
    0   0   0.9849951
    1   0   0.546427
    0   0   0.5440994    # --> doesn't make sense. Prob is more than 0.5
    0   0   0.5437889
    1   0   0.5417848
    0   0   0.5284112
    0   0   0.5252177
    0   1   0.5180776   # --> makes sense but is not consistent with above example
    0   1   0.5180704
    1   1   0.5180436
    1   1   0.5180436
    0   1   0.518043

This result doesn't make sense to me at all. The predicted class and predicted probabilities don't match. I've checked to make sure that I'm referencing the right column from the "probabilities" attribute matrix:

 test$Pred_Class
  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [98] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
attr(,"probabilities")
             1         0
6442 0.2369796 0.7630204
6443 0.2520246 0.7479754
6513 0.2322581 0.7677419
6801 0.2309437 0.7690563
6802 0.2244768 0.7755232
6954 0.2322450 0.7677550
6968 0.2537544 0.7462456
6989 0.2352477 0.7647523
7072 0.2322308 0.7677692
...
...
...

Maybe I am interpreting the probability incorrectly?

0 Answers
Related