API reference

Data

Data generation utilities.

class src.data.PolynomialDataGenerator(degree=3, coeff_range=(-0.5, 0.5), x_range=(-5, 5), noise_mean=0, noise_std=5, rng=None)

Bases: object

A class that generates polynomial data with noise.

Parameters:
  • degree (int) – The degree of the polynomial.

  • coeff_range (tuple[float, float]) – The range of coefficients for the polynomial.

  • x_range (tuple[float, float]) – The range of x values.

  • noise_mean (float) – The mean of the noise.

  • noise_std (float) – The standard deviation of the noise.

  • rng (Optional[np.random.Generator]) – The random number generator.

Variables:
  • degree (int) – The degree of the polynomial.

  • coeff_range (tuple[float, float]) – The range of coefficients for the polynomial.

  • x_range (tuple[float, float]) – The range of x values.

  • noise_mean (float) – The mean of the noise.

  • noise_std (float) – The standard deviation of the noise.

  • rng (np.random.Generator) – The random number generator.

  • coefficients (ndarray) – The coefficients of the polynomial.

generate(num_samples)

Generate polynomial data with noise.

Parameters:

num_samples (int) – The number of samples to generate.

Returns:

A tuple containing the generated x and y values.

Return type:

tuple[ndarray, ndarray]

Models

Module to define regression models.

class src.model.LinearRegressionModel(*args, **kwargs)

Bases: RegressionModel

Linear regression model for predicting continuous values.

This class inherits from the RegressionModel base class.

Methods:

_modify_input: Modifies the input data by adding a bias column. _compute_weight: Computes the weight vector using the normal equation. _compute_output: Computes the predicted output values.

Attributes:

weight: The weight vector learned during training.

class src.model.PolynomialRegressionModel(degree=3, *args, **kwargs)

Bases: LinearRegressionModel

A polynomial regression model that extends the LinearRegressionModel class.

Parameters: :type degree: int :param degree: The degree of the polynomial regression model. Must be greater than 0. :type degree: int

Methods:
_modify_input: Modifies the input features by transforming them into polynomial

features.

Parameters:

degree (int) –

class src.model.RegressionModel(*args, **kwargs)

Bases: ABC

Abstract base class for regression models.

fit(x, y)

Fit the regression model to the training data.

Parameters: :type x: NDArray[Shape[*, *], float64] :param x: Input features as a 2D array-like object. :type y: NDArray[Shape[*, *], float64] :param y: Target values as a 2D array-like object.

Returns: :rtype: RegressionModel :return: The fitted regression model.

Parameters:
  • x (NDArray[Shape[*, *], float64]) –

  • y (NDArray[Shape[*, *], float64]) –

Return type:

RegressionModel

fit_transform(x, y)

Fit the regression model to the training data and transform the input features.

Parameters: :type x: NDArray[Shape[*, *], float64] :param x: Input features as a 2D array-like object. :type y: NDArray[Shape[*, *], float64] :param y: Target values as a 2D array-like object.

Returns: :return transformed_x: Transformed input features as a 2D array-like object.

Return type:

NDArray[Shape[*, *], float64]

Parameters:
  • x (NDArray[Shape[*, *], float64]) –

  • y (NDArray[Shape[*, *], float64]) –

transform(x)

Transform the input features using the fitted regression model.

Parameters: :type x: NDArray[Shape[*, *], float64] :param x: Input features as a 2D array-like object.

Returns: :return transformed_x: Transformed input features as a 2D array-like object.

Return type:

NDArray[Shape[*, *], float64]

Parameters:

x (NDArray[Shape[*, *], float64]) –

src.model.create_model(model_type, *args, **kwargs)

Create a regression model based on the given model type.

Parameters: :type model_type: ModelType :param model_type: The type of regression model to create. :type model_type: ModelType :type args: :param args: Variable length argument list. :type kwargs: :param kwargs: Arbitrary keyword arguments.

Returns: :return: An instance of the created regression model. :rtype: RegressionModel

Raises: :raises ValueError: If the given model type is unknown.

Parameters:

model_type (ModelType) –

Return type:

RegressionModel

Config

This module contains the configuration classes.

class src.config.ModelType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Enumeration class representing different types of models.

LINEAR: str = 'linear'
POLYNOMIAL: str = 'polynomial'
class src.config.RunConfiguration(seed, num_samples, model_type, polynomial_degree)

Bases: object

Represent the configuration for a run.

Parameters:
  • seed (int) – The seed value for random number generation.

  • num_samples (int) – The number of samples to generate.

  • model_type (ModelType) – The type of model to use.

  • polynomial_degree (int) – The degree of the polynomial model.

model_type: ModelType
num_samples: int
polynomial_degree: int
seed: int
src.config.initialize_config(file_path)

Initialize the configuration for running the application.

Parameters:

file_path (str) – The path to the configuration file.

Returns:

The initialized configuration object.

Utils

Utility functions for the project.

src.utils.initialize_rng(seed)

Initialize a random number generator.

Parameters:

seed (int) – The seed value for random number generation.

Returns:

The random number generator.

Return type:

np.random.Generator

src.utils.read_yml(path)

Read a YAML file.

Parameters:

path (str) – The path to the YAML file.

Returns:

The data from the YAML file.

Return type:

dict