로딩
요청 처리 중입니다...

소프트맥스회귀_회귀의비용함수

 소프트맥스회귀_회귀의비용함수

import torch import torch.nn.functional as F torch.manual_seed(1) z = torch.FloatTensor([1, 2, 3]) hypothesis = F.softmax(z, dim=0) print(hypothesis) hypothesis.sum() z = torch.rand(3, 5, requires_grad=True) hypothesis = F.softmax(z, dim=1) print(hypothesis) y = torch.randint(5, (3,)).long() print(y) # 모든 원소가 0의 값을 가진 3 × 5 텐서 생성 y_one_hot = torch.zeros_like(hypothesis) y_one_hot.scatter_(1, y.unsqueeze(1), 1) print(y.unsqueeze(1)) cost = (y_one_hot * -torch.log(hypothesis)).sum(dim=1).mean() pr...