[R] resolve assignment_linter warnings (#8599)
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
require(xgboost)
|
||||
require(methods)
|
||||
|
||||
train = read.csv('data/train.csv',header=TRUE,stringsAsFactors = FALSE)
|
||||
test = read.csv('data/test.csv',header=TRUE,stringsAsFactors = FALSE)
|
||||
train = train[,-1]
|
||||
test = test[,-1]
|
||||
train <- read.csv('data/train.csv',header=TRUE,stringsAsFactors = FALSE)
|
||||
test <- read.csv('data/test.csv',header=TRUE,stringsAsFactors = FALSE)
|
||||
train <- train[,-1]
|
||||
test <- test[,-1]
|
||||
|
||||
y = train[,ncol(train)]
|
||||
y = gsub('Class_','',y)
|
||||
y = as.integer(y)-1 # xgboost take features in [0,numOfClass)
|
||||
y <- train[,ncol(train)]
|
||||
y <- gsub('Class_','',y)
|
||||
y <- as.integer(y)-1 # xgboost take features in [0,numOfClass)
|
||||
|
||||
x = rbind(train[,-ncol(train)],test)
|
||||
x = as.matrix(x)
|
||||
x = matrix(as.numeric(x),nrow(x),ncol(x))
|
||||
trind = 1:length(y)
|
||||
teind = (nrow(train)+1):nrow(x)
|
||||
x <- rbind(train[,-ncol(train)],test)
|
||||
x <- as.matrix(x)
|
||||
x <- matrix(as.numeric(x),nrow(x),ncol(x))
|
||||
trind <- 1:length(y)
|
||||
teind <- (nrow(train)+1):nrow(x)
|
||||
|
||||
# Set necessary parameter
|
||||
param <- list("objective" = "multi:softprob",
|
||||
@@ -23,21 +23,21 @@ param <- list("objective" = "multi:softprob",
|
||||
"nthread" = 8)
|
||||
|
||||
# Run Cross Validation
|
||||
cv.nrounds = 50
|
||||
bst.cv = xgb.cv(param=param, data = x[trind,], label = y,
|
||||
cv.nrounds <- 50
|
||||
bst.cv <- xgb.cv(param=param, data = x[trind,], label = y,
|
||||
nfold = 3, nrounds=cv.nrounds)
|
||||
|
||||
# Train the model
|
||||
nrounds = 50
|
||||
bst = xgboost(param=param, data = x[trind,], label = y, nrounds=nrounds)
|
||||
nrounds <- 50
|
||||
bst <- xgboost(param=param, data = x[trind,], label = y, nrounds=nrounds)
|
||||
|
||||
# Make prediction
|
||||
pred = predict(bst,x[teind,])
|
||||
pred = matrix(pred,9,length(pred)/9)
|
||||
pred = t(pred)
|
||||
pred <- predict(bst,x[teind,])
|
||||
pred <- matrix(pred,9,length(pred)/9)
|
||||
pred <- t(pred)
|
||||
|
||||
# Output submission
|
||||
pred = format(pred, digits=2,scientific=F) # shrink the size of submission
|
||||
pred = data.frame(1:nrow(pred),pred)
|
||||
names(pred) = c('id', paste0('Class_',1:9))
|
||||
pred <- format(pred, digits=2,scientific=F) # shrink the size of submission
|
||||
pred <- data.frame(1:nrow(pred),pred)
|
||||
names(pred) <- c('id', paste0('Class_',1:9))
|
||||
write.csv(pred,file='submission.csv', quote=FALSE,row.names=FALSE)
|
||||
|
||||
@@ -127,7 +127,7 @@ param <- list("objective" = "multi:softprob",
|
||||
cv.nrounds <- 5
|
||||
cv.nfold <- 3
|
||||
|
||||
bst.cv = xgb.cv(param=param, data = trainMatrix, label = y,
|
||||
bst.cv <- xgb.cv(param=param, data = trainMatrix, label = y,
|
||||
nfold = cv.nfold, nrounds = cv.nrounds)
|
||||
```
|
||||
> As we can see the error rate is low on the test dataset (for a 5mn trained model).
|
||||
@@ -135,8 +135,8 @@ bst.cv = xgb.cv(param=param, data = trainMatrix, label = y,
|
||||
Finally, we are ready to train the real model!!!
|
||||
|
||||
```{r modelTraining}
|
||||
nrounds = 50
|
||||
bst = xgboost(param=param, data = trainMatrix, label = y, nrounds=nrounds)
|
||||
nrounds <- 50
|
||||
bst <- xgboost(param=param, data = trainMatrix, label = y, nrounds=nrounds)
|
||||
```
|
||||
|
||||
Model understanding
|
||||
|
||||
Reference in New Issue
Block a user