Python Classifier Decision Boundary Code Here is my code: I'd like to see a decision boundary where my model predicts the six points in Python code please. import numpy as np import torch import...


Python Classifier Decision Boundary Code


Here is my code:


I'd like to see a decision boundary where my model predicts the six points inPython code please.


import numpy as np
import torch
import torch.nn as nn
import matplotlib.pyplot as plt




X = torch.from_numpy(np.array([[-1,0.5],[-1.2,0.3],[1,1],[0.9,1.2],[0.1,-1],[0.2,-0.5]])).float()


Y = torch.from_numpy(np.array(([0,0,1,1,2,2])))




train_data = torch.utils.data.TensorDataset(X, Y)
test_data = torch.utils.data.TensorDataset(X, Y)


train_loader = torch.utils.data.DataLoader(train_data, batch_size=6, shuffle=True)
test_loader = torch.utils.data.DataLoader(test_data, batch_size=6, shuffle=True)




myModel0 = nn.Sequential(*[nn.Linear(2,2), nn.ReLU(), nn.Linear(2,3)])
myLoss = nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(myModel0.parameters(), lr=0.01)


epoch_loss = []
step_loss = []
sum(p.numel() for p in myModel0.parameters() if p.requires_grad)




for epoch in range(1000):
running_loss = 0.0
miniBatch = 0
for x,y in train_loader:
optimizer.zero_grad()
score = myModel0(x)
loss = myLoss(score, y.type(torch.LongTensor))
loss.backward()
optimizer.step()
running_loss += loss.detach().numpy()
miniBatch += 1
step_loss.append(loss.detach().item())
epoch_loss.append(running_loss/len(train_loader))



Jun 04, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here