我正在尝试使用R -language中的内置函数来实现andrew ng的机器学习程序。
我陷入了正规化的逻辑回归中。
将glmnet()函数应用于ex2data2文件时,我得不到正确答案。
对于ex2data2.txt,请点击此链接。
https://github.com/merwan/ml-class/tree/master/mlclass-ex2。
这是我的代码
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)
请帮帮我。