#逻辑回归
import torch
X = torch.tensor([[1,0,0],[1,1,0],[1,0,1],[1,1,1]],dtype = torch.float32)
w = torch.tensor([-0.2,0.15,0.15],dtype = torch.float32)
def LogisticR(X,w):
zhat = torch.mv(X,w) #首先是线性回归
sigma = torch.sigmoid(zhat)#逻辑回归
andhat = torch.tensor([int(x) for x in sigma>=0.5], dtype = torch.float32) #列表推导式
return sigma,andhat
sigma, andhat = LogisticR(X,w)
print(sigma)
print(andhat)
逻辑回归
最新推荐文章于 2024-07-13 09:24:46 发布