BaseImpl

class jlpy.pytorch.base.linear_regression.base_impl.BaseImpl

Bases: object

Deep Learning Linear Regression Base Implemetation.

  1. Generate a demo training and validation dataset.

  2. Build a linear regression model.

  3. Train the LRModel.

    • Iterate over epoch.

    • Setup training mode.
      • Iterate over mini-batch of training set.

      • Optim.zero_grad.

      • Model forward.

      • Loss function.

      • Loss backward.

      • Optim step.

    • Setup validation mode.
      • Torch.no_grad.

      • Iterate over mini-batch of validation set.

      • Model forward.

      • Loss function.

  4. Plot the result.

Methods

__init__

Construct a class instance.

fit

Train the model.

plot

Plot the loss.

show

Show the dataset.

__init__(*, bsize: int = 32, nepoch: int = 2, gap: int = 50, ws: list[float] = [2, -3.4], **kwargs: float) None

Construct a class instance.

show(data: DataLoader[T], loop: int = 0) None

Show the dataset.

Parameters:
  • data (DataLoader[T]) – Dataset.

  • loop (int) – Loops for iterate over dataset.

Returns:

None

Return type:

None

plot() None

Plot the loss.

Returns:

None

Return type:

None

fit() None

Train the model.

Returns:

None

Return type:

None