Overview
To avoid the memory problem, I converted the document term matrix to a sparse matrix with the "matrix" package, using the code snippet below:
library(matrix)
documentTermMatrixFrame <- Matrix(documentTermMatrixFrame, sparse = TRUE)
but when I try to use this matrix as input for the ranger () function for the "ranger" package, using the following code:
library(ranger)
trainSet <- documentTermMatrixFrame[1:750,]
testSet <- documentTermMatrixFrame[751:999,]
fit <- ranger(trainingColumnNames, data=trainSet,write.forest=TRUE)
I get an error:
Error in as.data.frame.default(data) :
cannot coerce class "structure("dgCMatrix", package = "Matrix")" to a data.frame
Dataset
This is a sample dataset that I am using.
<html>
<table style="width:100%">
<tr>
<th>nitemid</th>
<th>sUnSpsc</th>
<th>productDescription</th>
</tr>
<tr>
<td>7460893</td>
<td>26121609Network cable </td>
<td>Category 6A, Advanced MaTriX, 4-pair, 23 AWG, U/UTP copper cable, Plenum (CMP) Rated, White, 1000ft/305m ""</td>
</tr>
<tr>
<td>7460456</td>
<td>26121709Network cable </td>
<td>Shielded marine MUD-resistant armored copper cable, category 7 S/FTP, low smoke zero halogen (LSZH), 4-pair, conductors are 22 AWG construction with foamed PE insulation, twisted in pairs</td>
</tr>
<tr>
<td>7460856</td>
<td>26121890Inter connect cable </td>
<td>1 PC. = 100 M 2 X 1.5 QMM, 100M SPECIAL DESIGN TO UL CLASS 2 YELLOW TPE OIL-RESISTANT AS-INTERFACE SHAPED CABLE</td>
</tr>
</html>
Run codeAfter preliminary processing of the description in the data set using the removal of the temporary word, punctuation removal will be created, creation, etc. .... a document-matrix matrix will be created, which, in turn, will be converted into a sparse matrix.
sample Documnent-term matrix for a dataset
terms
doc advance category ..... ..... ....... ....... ....... twist
1 1 1 0
2 0 1 1
3 0 0 0
Question
raanger()?
-
Advance