I am trying to implement andrew ng's machine learning programs using built in functions in R -language .
I got stuck in logistic regression with regularization .
I am not getting the right answer while applying glmnet() function to ex2data2 file .
For ex2data2.txt click on this link .
https://github.com/merwan/ml-class/tree/master/mlclass-ex2.
Here goes my code
mapFeature <- function(x1,x2,degree=6){
out <- sapply(0:degree,function(i)
sapply(0:i, function(j)
x1^(i-j) * x2^j
)
)
return(data.frame(matrix(unlist(out), nrow=length(x1))))
}
mydata = read.csv("C:/Users/xyz/Desktop/ml-class-master/ml-class-master/mlclass-ex2/ex2data2.txt",header=FALSE, sep=",");
X <- mapFeature(mydata[,c(1)],mydata[,c(2)]);
X$y<-mydata$V3;
x<-as.matrix(X[1:28])
fit=cv.glmnet(x,as.vector(X$y),nlambda=1,alpha=0.7,family="binomial", intercept=FALSE);
coef(fit)
Please help me .