<pre name="code" class="python">#alpha error theta
#虽然是python 标签 但缺少
sigmoid <- function(x){
return (1.0/(1+exp(-x)))
}
#用什么样的优化算法 1 gradient descent 2 stochastic gradient descent
# 3
controlnumber = 3
#set max iterator times
maxIter = 200
dir = "E:/A_Ten algorithm of machine learning/logistic.txt"
#运行结果存储
pdf("E:/A_Ten algorithm of machine learning/logistic.pdf")
original.data = read.table(file = dir, header = FALSE)
head(original.data)
#original.data = as.matrix(original.data)
#data x
s = rep(1,nrow(original.data))
train_x = cbind(s,original.data[,c(1,2)])
#data labels y 0/1
train_y = original.data[,3]
# parameter theta
theta = rep(1,length(train_x[1,]))
#Conversion train_x to matrix
train_x = as.matrix(train_x)
#Conversion theta to matrix
theta = as.matrix(theta)
#plot points
plot(train_x[,2],train_x[,3],col = "red",xlab =
R语言实现 logistic 模型
最新推荐文章于 2023-10-20 22:10:15 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)