Skip to content

Instantly share code, notes, and snippets.

@selva86
Created March 25, 2017 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selva86/972bb3c4f0ed9c24370a15ad68a85795 to your computer and use it in GitHub Desktop.
Save selva86/972bb3c4f0ed9c24370a15ad68a85795 to your computer and use it in GitHub Desktop.
Preparatory code for lasso regression lecture
# prep training and test datasets
set.seed(100)
trainRows <- createDataPartition(prostate$lpsa, p=.75, list=FALSE)
trainData <- prostate[trainRows, ]
testData <- prostate[-trainRows, ]
# prepare X and Y matrices separately
train_x <- as.matrix(trainData[, colnames(trainData) %ni% c("lpsa", "train")])
train_y <- as.matrix(trainData[, "lpsa"])
test_x <- as.matrix(testData[, colnames(trainData) %ni% c("lpsa", "train")])
test_y <- as.matrix(testData[, "lpsa"])
# grid
grid=10^seq(10, -2, length=100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment