# Matrix class not being recognized

I have a data frame, and I am only interested in the numerical variables (variable class is double):

## Example

A    B    C    D    E
0.13 2.22 3.44 3.30 6.54
3.55 4.23 0.43 5.33 3.55
...


I want to build a linear regression xgboost model, so I converted the data frame to a dense matrix.

I took out all categorical variables from my data, and am left with the five variables of interest. But I can't seem to be able to use the dense matrix, despite it being a type of input that xgboost accepts. See here. I am instead getting this error:

## Error

"Error in xgb.DMatrix(train_mat[, -n], label = train_mat[, n]) : [23:57:13] amalgamation/../dmlc-core/src/io/local_filesys.cc:66: LocalFileSystem.GetPathInfo 2007 Error:No such file or directory".

## Code

train_mat <- as.matrix(subset(train, select = -c(Genre, Publisher, Rank, Name, Platform)))

lm.boosted <- xgb.train(data = train_mat, booster= "gblinear", max_depth=3, nthread=1, nrounds = 2, eval_metric="error", eval_metric= "rmse", objective= "reg:linear")


I tried to convert to a xgb.DMatrix, but I am not clear on what it's asking for to do the conversion.

train_mat <- xgb.DMatrix(data = train_mat, label= train\$Global_Sales)


How do I input data into xgboost?

Following this example:

Suppose the last column in train_mat is the label that needs to be predicted, i.e. Global_Sales, then you construct the xgb.DMatrix as:

n <- ncol(train_mat)    # or if not the last, the position of the label column
dtrain <- xgb.DMatrix(train_mat[,-n], label=train_mat[,n])


To train the model, simply pass dtrain to the data parameter:

lm.boosted <- xgb.train(data = dtrain, booster= "gblinear", max_depth=3, nthread=1, nrounds = 2, eval_metric="error", eval_metric= "rmse", objective= "reg:linear")

• Global_Sales is the last column in train_mat. But sorry, I get the following error: "Error in xgb.DMatrix(train_mat[, -n], label = train_mat[, n]) : [23:57:13] amalgamation/../dmlc-core/src/io/local_filesys.cc:66: LocalFileSystem.GetPathInfo 2007 Error:No such file or directory". I can run the example in the link you posted, so there must be something wrong with the matrix I am creating for my model. Sep 25 '17 at 3:59
• The error looks mysterious to me. Are you able to read the data in? OR when running in console, does train_mat load? Sep 25 '17 at 14:52
• Yeah, I am able to interact with the data fully in Rstudio. Train mat loads in console as well. If nothing else, I'll get in touch with the xgboost people. Sep 25 '17 at 17:36

I got some help from the xgboost issues page on Github; thread here.

Made the following change to resolve the error:

train_mat <- data.matrix(subset(train, select = -c(Genre, Publisher, Rank, Name, Platform)))