How to use BCELoss, MSELoss (pytorch)



Python
library
pip

MeCab

numpy
digitize

mgrid

pad

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

scipy
interpolate
tkinter
postscript

image display

frame, grid

other
linear interpolation

OpenAI gym
CartPole-v0


Release date:2022/2/28         

In Japanese


■Description of BCELoss, MSELoss

Calculates the error function used in machine learning.

■Specific example using BCELoss, MSELoss

<Binary Cross Entropy Loss>

import torch
import torch.nn as nn

loss = nn.BCELoss()
estimate = torch.tensor([0.7,0.2,0.1]) # estimate value
real = torch.tensor([1.0, 0, 0]) # true value or target value

print(loss(estimate , real))

 ⇒ tensor(0.2284)


The calculation is below


<MSE:Mean Square Error>
The format is the same as above, changing the "BCE Loss" part to "MSE Loss".


import torch
import torch.nn as nn

loss = nn.MSELoss()
estimate = torch.tensor([0.7,0.2,0.1]) # estimate value
real = torch.tensor([1.0, 0, 0]) # true value or target value

print(loss(estimate , real))

 ⇒ tensor(0.0467)


The calculation is below










List of related articles



Python
library
pip

MeCab

numpy
digitize

mgrid

pad

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

scipy
interpolate
tkinter
postscript

image display

frame, grid

other
linear interpolation

OpenAI gym
CartPole-v0