Created
February 19, 2016 19:00
-
-
Save adini121/636828fe5dd4282e25df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(lars) #load lars library | |
# load data from csv file | |
fullData <- read.csv('/Users/adityanisal/Dropbox/ExtractedResultFiles/CSV/fireplace-mv1.csv') | |
# display data | |
fullData | |
# remove "null" columns (columns with all 0s) | |
M <- fullData[,colSums(fullData^2) !=0] | |
M | |
# Take all columns (features) except the last solutionVector | |
x <- M[,c(1:8)] | |
x | |
# solution vector | |
y <- M[,9] | |
#normalize with mean =0 and sd=1 | |
fin_x = apply(x, 2, function(aa){ | |
return( ((aa - mean(aa))/sd(aa))) | |
}) | |
# create lasso model | |
fit <- lars(fin_x,y,type = "lasso") | |
# show steps | |
fit | |
# show standardized coefficients | |
coef(fit) | |
# plot lasso path | |
dev.new() | |
plot(fit,breaks = FALSE) | |
legend('topleft',inset=c(0.05,0),names(M[,c(-9)]),lty = 1:length(names(M[,c(-9)])),col=1:8,lwd=1,box.lty=0,cex=.7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment