# System thinking with Linear Regression

``````# data collection that converts into Social Transmedia

import torch
import torch.nn as nn
import torch.optim as optim

x = Variable(torch.Tensor([[1],[2],[3],[4]]))
y = Variable(torch.Tensor([[2],[4],[6],[8]]))

class SocialTransmedia(nn.Module):
def __init__(self, input_size, output_size):
super(SocialTransmedia, self).__init__()
self.linear = nn.Linear(input_size, output_size)

def forward(self, x):
y_predict = self.linear(x)
return y_predict

model = SocialTransmedia(1,1)
criteria = nn.MSELoss()
optimizer = optim.SGD(model.parameters(), 0.01)

for epoch in range(500):
y_predict = model(x)
loss = criteria(y_predict, y)
loss.backward()
optimizer.step()
print(epoch, float(loss.data[0]))

test = Variable(torch.Tensor([[20]]))
z = model.forward(test)
print(float(z.data[0]))

# 39.88399887084961

# Logistic Regression

import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as f

x = Variable(torch.Tensor([[25],[35],[45],[15]]))
y = Variable(torch.Tensor([[0],[1],[1],[0]]))

class SocialTransmedia(nn.Module):
def __init__(self, input_size, output_size):
super(SocialTransmedia, self).__init__()
self.linear = nn.Linear(input_size, output_size)

def forward(self, x):
y_predict = f.sigmoid(self.linear(x))
return y_predict

model = SocialTransmedia(1,1)
criteria = nn.BCELoss()
optimizer = optim.SGD(model.parameters(), 0.01)

for epoch in range(500):
y_predict = model(x)
loss = criteria(y_predict, y)
loss.backward()
optimizer.step()
print(epoch, float(loss.data[0]))

test = Variable(torch.Tensor([[20]]))
z = model.forward(test)
print(float(z.data[0]))
``````