Reputation: 728
I have the classic titanic data. Here is the description of the cleaned data.
> str(titanic)
'data.frame': 887 obs. of 7 variables:
$ Survived : Factor w/ 2 levels "No","Yes": 1 2 2 2 1 1 1 1 2 2 ...
$ Pclass : int 3 1 3 1 3 3 1 3 3 2 ...
$ Sex : Factor w/ 2 levels "female","male": 2 1 1 1 2 2 2 2 1 1 ...
$ Age : num 22 38 26 35 35 27 54 2 27 14 ...
$ Siblings.Spouses.Aboard: int 1 1 0 1 0 0 0 3 0 1 ...
$ Parents.Children.Aboard: int 0 0 0 0 0 0 0 1 2 0 ...
$ Fare : num 7.25 71.28 7.92 53.1 8.05 ...
I first split the data.
smp_size <- floor(0.8 * nrow(titanic))
set.seed(123)
train_ind <- sample(seq_len(nrow(titanic)), size = smp_size)
train <- titanic[train_ind, ]
test <- titanic[-train_ind, ]
Then I changed Survived column to -1 and 1.
train$Survived_ab <- ifelse(train$Survived == 'No', -1, 1)
test$Survived_ab <- ifelse(test$Survived == 'No', -1, 1)
Finally, I ran adaboost algorithm using JOUSBoost
package.
dt_ab <- adaboost(X = data.matrix(train[,2:7]), y = train$Survived_ab)
Here are the results.
> print(dt_ab)
NULL
NULL
Dependent Variable:
No of trees:100
The weights of the trees are:
Tried to predict using the model.
predict_ab <- predict(dt_ab, data.matrix(test[,2:7]), type = 'response')
And got the error below.
Error in predict_adaboost_(tree_list, coeff_vector, newdata, num_examples, : Not compatible with requested type: [type=NULL; target=double].
Why is this?
Upvotes: 1
Views: 83