Linear Regression
Module: deeprai.models.regression.linear_regression
This module introduces a simple Linear Regression model. Linear Regression is a statistical technique commonly used for modeling and analyzing relationships between two variables.
Class: LinearRegression
A class representation of the linear regression model.
1. Initializer: __init__(self)
Description:
Initializes the LinearRegression
class.
Attributes:
- fitted_vals (
list
): A list to store the results after the model has been fitted. This is primarily the coefficients of the linear equation.
Example:
from deeprai.models.regression.linear_regression import LinearRegression
model = LinearRegression()
2. Method: fit(self, x_vals, y_vals)
Description:
Fit the model to the given x_vals
and y_vals
using linear regression.
Parameters:
-
x_vals (
list
ornp.ndarray
): The input values or features. -
y_vals (
list
ornp.ndarray
): The output values or labels.
Returns:
list
: Coefficients of the linear equation.
Example:
model.fit(x_vals=[1, 2, 3], y_vals=[2, 4, 6])
3. Method: run(self, x_val)
Description:
Use the previously fitted model to predict the output for a given x_val
.
Parameters:
- x_val (
float
): The input value for which the prediction is desired.
Returns:
float
: Predicted value based on the linear regression equation.
Example:
predicted_val = model.run(4)
print(predicted_val)
No Comments