import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as func
import torch.optim as opt
#from google.colab import drive
#drive.mount('/content/drive')
# Seed 고정
torch.manual_seed(1)
<torch._C.Generator at 0x7f375ac5eb70>
1 Data loading
1
2
0
2
3
0
3
1
0
4
3
1
5
3
1
6
2
1
# Data 수동으로 입력하기
x_train = torch.FloatTensor([[1, 2], [2, 3], [3, 1], [4, 3], [5, 3], [6, 2]])
y_train = torch.FloatTensor([[0], [0], [0], [1], [1], [1]])
print(x_train)
print(x_train.shape)
print(y_train)
print(y_train.shape)
# Model 설계
class Logistic(nn.Module):
def __init__(self, num_inputs, num_outputs):
super().__init__()
self.linear = nn.Linear(num_inputs, num_outputs)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
return self.sigmoid(self.linear(x))
# Model 초기화 (입력 dim, 출력 dim)
model = Logistic(2, 1)