Can somebody help me please? I want to prepare data for XGBoost prediction so I need edit factor datas. I use sparse.model.matrix() but there is a problem. I don't know, why function ignored some of the columns. I'll try to explain. I have dataset dataset with many variables, but now these 3 are important:
- Tsunami.Event.Validity - Factor with 6 classes: -1,0,1,2,3,4
- Tsunami.Cause.Code - Factor with 6 classes: 0,1,2,3,4,5
- Total.Death.Description - Factor with 5 classes: 0,1,2,3,4
But when I use sparse.model.matrix() I get matrix only with 15 columns not 6+6+5=17 as expected. Can somebody give ma an advice?
sp_matrix = sparse.model.matrix(Deadly ~ Tsunami.Event.Validity + Tsunami.Cause.Code + Total.Death.Description -1, data = datas)
str(sp_matrix)
Output:
Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
..@ i : int [1:2510] 0 1 2 3 4 5 6 7 8 9 ...
..@ p : int [1:16] 0 749 757 779 823 892 1495 2191 2239 2241 ...
..@ Dim : int [1:2] 749 15
..@ Dimnames:List of 2
.. ..$ : chr [1:749] "1" "2" "3" "4" ...
.. ..$ : chr [1:15] "Tsunami.Event.Validity-1" "Tsunami.Event.Validity0" "Tsunami.Event.Validity1" "Tsunami.Event.Validity2" ...
..@ x : num [1:2510] 1 1 1 1 1 1 1 1 1 1 ...
..@ factors : list()
..$ assign : int [1:15] 0 1 1 1 1 1 2 2 2 2 ...
..$ contrasts:List of 3
.. ..$ Tsunami.Event.Validity : chr "contr.treatment"
.. ..$ Tsunami.Cause.Code : chr "contr.treatment"
.. ..$ Total.Death.Description: chr "contr.treatment"