Pytorch 6

罗切斯特回归模型

加了激活函数

加了激活函数之后类

python 复制代码
class LogisticRegressionModel(torch.nn.Module):
    def __init__(self):
        super(LogisticRegressionModel, self).__init__()
        self.linear = torch.nn.Linear(1,1)
 
    def forward(self, x):
        # y_pred = F.sigmoid(self.linear(x))
        y_pred = torch.sigmoid(self.linear(x))
        return y_pred

这里以sigmoid激活函数为例,具体的激活函数还是查资料

损失函数

python 复制代码
criterion = torch.nn.BCELoss(size_average = False) 

也是接受一个参数,是否求平均值

求平均值会影响到dw和db是否要乘1/n,会影响到学习率的设置,如果求均值则偏导也有1/n

相关推荐
冬哥聊AI26 分钟前
放弃 Spring AI?这 3 个开源框架,才是让 SpringBoot 玩转 AI Agent 的正解
人工智能
小爷毛毛_卓寿杰26 分钟前
当 max_tokens=1 遇上 reasoning 模型:从 Xagent 一次“测试连接“按钮的失败说起
人工智能
用户51914958484527 分钟前
Flex QR Code Generator 漏洞利用工具 CVE-2025-10041
人工智能·aigc
蝎子莱莱爱打怪1 小时前
AI Agent 相关知识扫盲:16 个概念+11张图+38个开源项目推荐
人工智能·github·agent
甲维斯2 小时前
Fable+Codex 《坦克大战3D》双端发布了!
人工智能·ai编程·游戏开发
掘金一周2 小时前
企业中要做智能体,最佳的方案是什么? | 沸点周刊 6.18
前端·人工智能·ai编程
雪隐3 小时前
个人电脑玩AI-04让5060 Ti给你打工——本地claude code编程助理
人工智能·后端
洛宇3 小时前
再谈 AI 时代,程序员的失眠问题。
人工智能
百度Geek说3 小时前
harness-pilot 给代码库加一套"规则说明书"和"自动检查器"
人工智能