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

相关推荐
华农DrLai2 小时前
什么是LLM做推荐的三种范式?Prompt-based、Embedding-based、Fine-tuning深度解析
人工智能·深度学习·prompt·transformer·知识图谱·embedding
2301_764441332 小时前
LISA时空跃迁分析,地理时空分析
数据结构·python·算法
东北洗浴王子讲AI2 小时前
GPT-5.4辅助算法设计与优化:从理论到实践的系统方法
人工智能·gpt·算法·chatgpt
超低空3 小时前
OpenClaw Windows 安装详细教程
人工智能·程序员·ai编程
恋猫de小郭3 小时前
你的代理归我了:AI 大模型恶意中间人攻击,钱包都被转走了
前端·人工智能·ai编程
yongyoudayee3 小时前
2026 AI CRM选型大比拼:四大架构路线实测对比
人工智能·架构
chushiyunen3 小时前
python rest请求、requests
开发语言·python
cTz6FE7gA3 小时前
Python异步编程:从协程到Asyncio的底层揭秘
python
baidu_huihui4 小时前
在 CentOS 9 上安装 pip(Python 的包管理工具)
开发语言·python·pip
高洁014 小时前
多模态AI模型融合难?核心问题与解决思路
人工智能·深度学习·机器学习·数据挖掘·transformer