Title: | I/O Operations with Sparse Matrices |
---|---|
Description: | Fast 'SVMlight' reader and writer. 'SVMlight' is most commonly used format for storing sparse matrices (possibly with some target variable) on disk. For additional information about 'SVMlight' format see <http://svmlight.joachims.org/>. |
Authors: | Dmitriy Selivanov [aut, cre], Felix Riedel [aut] |
Maintainer: | Dmitriy Selivanov <[email protected]> |
License: | GPL (>= 2) | file LICENSE |
Version: | 1.0.1 |
Built: | 2024-11-11 05:30:20 UTC |
Source: | https://github.com/rexyai/sparsio |
Reads and writes svmlight files. Notice that current implementation can't handle comments in svmlight files during reading.
read_svmlight(file, type = c("CsparseMatrix", "RsparseMatrix", "TsparseMatrix"), zero_based = TRUE, ncol = NULL) write_svmlight(x, y = rep(0, nrow(x)), file, zero_based = TRUE)
read_svmlight(file, type = c("CsparseMatrix", "RsparseMatrix", "TsparseMatrix"), zero_based = TRUE, ncol = NULL) write_svmlight(x, y = rep(0, nrow(x)), file, zero_based = TRUE)
file |
string, path to svmlight file |
type |
target class for sparse matrix. |
zero_based |
|
ncol |
number of columns in target matrix. |
x |
input sparse matrix. Should inherit from |
y |
target values. Labels must be an integer or numeric of the same length as number of rows in |
library(Matrix) library(sparsio) i = 1:8 j = 1:8 v = rep(2, 8) x = sparseMatrix(i, j, x = v) y = sample(c(0, 1), nrow(x), replace = TRUE) f = tempfile(fileext = ".svmlight") write_svmlight(x, y, f) x2 = read_svmlight(f, type = "CsparseMatrix") identical(x2$x, x) identical(x2$y, y)
library(Matrix) library(sparsio) i = 1:8 j = 1:8 v = rep(2, 8) x = sparseMatrix(i, j, x = v) y = sample(c(0, 1), nrow(x), replace = TRUE) f = tempfile(fileext = ".svmlight") write_svmlight(x, y, f) x2 = read_svmlight(f, type = "CsparseMatrix") identical(x2$x, x) identical(x2$y, y)