Skip to content

linear_regression

LinearRegression(input_size, output_size, learning_rate=0.001, loss=None)

Bases: SupervisedIncrementalLearner

Linear regression learner.

Initialize the learner.

Parameters:

Name Type Description Default
input_size int

The size of the input.

required
output_size int

The size of the output.

required
learning_rate float

The learning rate.

0.001
loss Module | None

The loss function.

None
Source code in src/flowcean/learners/linear_regression.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def __init__(
    self,
    input_size: int,
    output_size: int,
    learning_rate: float = 1e-3,
    loss: nn.Module | None = None,
) -> None:
    """Initialize the learner.

    Args:
        input_size: The size of the input.
        output_size: The size of the output.
        learning_rate: The learning rate.
        loss: The loss function.
    """
    self.model = nn.Linear(input_size, output_size)
    self.loss = loss or nn.MSELoss()
    self.optimizer = SGD(
        self.model.parameters(),
        lr=learning_rate,
    )