Regression

Regression classes for crossplot analysis.

This module provides various regression classes that can fit data and be used for prediction. Each regression class can be used independently or as part of crossplot visualizations.

class logsuite.analysis.regression.RegressionBase(locked_params=None)[source]

Bases: ABC

Base class for all regression types.

Parameters:

locked_params (dict[str, float] | None)

abstractmethod fit(x, y)[source]

Fit the regression model to data.

Args:

x: Independent variable values y: Dependent variable values

Returns:

Self for method chaining

Parameters:
  • x (ArrayLike)

  • y (ArrayLike)

Return type:

RegressionBase

abstractmethod predict(x)[source]

Predict y values for given x values.

Args:

x: Independent variable values

Returns:

Predicted y values

Parameters:

x (ArrayLike)

Return type:

ndarray

abstractmethod equation()[source]

Return the regression equation as a string.

Return type:

str

lock_params(**params)[source]

Lock one or more parameters to fixed values.

Locked parameters will not be optimized during fitting.

Args:

**params: Parameter names and their locked values.

Returns:

Self for method chaining.

Example:
>>> reg = LinearRegression()
>>> reg.lock_params(slope=2.0)
>>> reg.fit(x, y)  # Will fit intercept only, slope fixed at 2.0
Parameters:

params (float)

Return type:

RegressionBase

unlock_params(*param_names)[source]

Unlock one or more parameters.

Args:

*param_names: Names of parameters to unlock. If none provided, unlocks all.

Returns:

Self for method chaining.

Example:
>>> reg.unlock_params('slope')  # Unlock specific parameter
>>> reg.unlock_params()  # Unlock all parameters
Parameters:

param_names (str)

Return type:

RegressionBase

get_locked_params()[source]

Get currently locked parameters.

Returns:

Dictionary of locked parameter names and values

Return type:

dict[str, float]

is_param_locked(param_name)[source]

Check if a parameter is locked.

Args:

param_name: Name of the parameter to check

Returns:

True if parameter is locked, False otherwise

Parameters:

param_name (str)

Return type:

bool

get_plot_data(x_range=None, num_points=100)[source]

Get x and y data for plotting the regression line.

Parameters:
  • x_range (tuple[float, float], optional) – Tuple of (x_min, x_max) for the plot range. If None, uses the stored x_range from fitting. If stored x_range is also None, raises an error.

  • num_points (int, default 100) – Number of points to generate for the line.

Returns:

Tuple of (x_values, y_values) for plotting.

Return type:

tuple[np.ndarray, np.ndarray]

Raises:

ValueError – If model is not fitted or x_range cannot be determined.

class logsuite.analysis.regression.LinearRegression(locked_params=None)[source]

Bases: RegressionBase

Linear regression: y = a*x + b

Example:
>>> reg = LinearRegression()
>>> reg.fit([1, 2, 3, 4], [2, 4, 6, 8])
>>> reg.predict([5, 6])
array([10., 12.])
>>> print(reg.equation())
y = 2.00x + 0.00
>>> print(f"R² = {reg.r_squared:.3f}")
R² = 1.000

# Lock slope to force through origin with specific slope >>> reg = LinearRegression(locked_params={‘slope’: 2.0}) >>> reg.fit(x, y) # Only fits intercept

Parameters:

locked_params (dict[str, float] | None)

fit(x, y)[source]

Fit linear regression model.

Args:

x: Independent variable values y: Dependent variable values

Returns:

Self for method chaining

Parameters:
  • x (ArrayLike)

  • y (ArrayLike)

Return type:

LinearRegression

predict(x)[source]

Predict y values using linear model.

Args:

x: Independent variable values

Returns:

Predicted y values

Parameters:

x (ArrayLike)

Return type:

ndarray

equation()[source]

Return the linear equation as a string.

Return type:

str

class logsuite.analysis.regression.LogarithmicRegression(locked_params=None)[source]

Bases: RegressionBase

Logarithmic regression: y = a*ln(x) + b

Note: Only valid for positive x values.

Example:
>>> reg = LogarithmicRegression()
>>> reg.fit([1, 2, 4, 8], [1, 2, 3, 4])
>>> reg.predict([16])
array([5.])

# Lock the coefficient >>> reg = LogarithmicRegression(locked_params={‘a’: 1.5}) >>> reg.fit(x, y) # Only fits b

Parameters:

locked_params (dict[str, float] | None)

fit(x, y)[source]

Fit logarithmic regression model.

Args:

x: Independent variable values (must be positive) y: Dependent variable values

Returns:

Self for method chaining

Parameters:
  • x (ArrayLike)

  • y (ArrayLike)

Return type:

LogarithmicRegression

predict(x)[source]

Predict y values using logarithmic model.

Args:

x: Independent variable values (must be positive)

Returns:

Predicted y values

Parameters:

x (ArrayLike)

Return type:

ndarray

equation()[source]

Return the logarithmic equation as a string.

Return type:

str

class logsuite.analysis.regression.ExponentialRegression(locked_params=None)[source]

Bases: RegressionBase

Exponential regression: y = a*e^(b*x)

Note: Only valid for positive y values.

Example:
>>> reg = ExponentialRegression()
>>> reg.fit([0, 1, 2, 3], [1, 2.7, 7.4, 20.1])
>>> reg.predict([4])
array([54.6])

# Lock the base value >>> reg = ExponentialRegression(locked_params={‘a’: 1.0}) >>> reg.fit(x, y) # Only fits b

Parameters:

locked_params (dict[str, float] | None)

fit(x, y)[source]

Fit exponential regression model.

Args:

x: Independent variable values y: Dependent variable values (must be positive)

Returns:

Self for method chaining

Parameters:
  • x (ArrayLike)

  • y (ArrayLike)

Return type:

ExponentialRegression

predict(x)[source]

Predict y values using exponential model.

Args:

x: Independent variable values

Returns:

Predicted y values

Parameters:

x (ArrayLike)

Return type:

ndarray

equation()[source]

Return the exponential equation as a string.

Return type:

str

class logsuite.analysis.regression.PolynomialRegression(degree=2, locked_params=None)[source]

Bases: RegressionBase

Polynomial regression: y = a_n*x^n + a_(n-1)*x^(n-1) + … + a_1*x + a_0

Example:
>>> reg = PolynomialRegression(degree=2)
>>> reg.fit([1, 2, 3, 4], [1, 4, 9, 16])
>>> reg.predict([5])
array([25.])
>>> print(reg.equation())
y = 1.00x² + 0.00x + 0.00

# Lock specific coefficients (indexed from highest to lowest degree) >>> reg = PolynomialRegression(degree=2, locked_params={‘c0’: 1.0}) # Lock x² coefficient >>> reg.fit(x, y) # Only fits c1 and c2

Parameters:
fit(x, y)[source]

Fit polynomial regression model.

Args:

x: Independent variable values y: Dependent variable values

Returns:

Self for method chaining

Parameters:
  • x (ArrayLike)

  • y (ArrayLike)

Return type:

PolynomialRegression

predict(x)[source]

Predict y values using polynomial model.

Args:

x: Independent variable values

Returns:

Predicted y values

Parameters:

x (ArrayLike)

Return type:

ndarray

equation()[source]

Return the polynomial equation as a string.

Return type:

str

class logsuite.analysis.regression.PowerRegression(locked_params=None)[source]

Bases: RegressionBase

Power regression: y = a*x^b

Note: Only valid for positive x and y values.

Example:
>>> reg = PowerRegression()
>>> reg.fit([1, 2, 3, 4], [1, 4, 9, 16])
>>> reg.predict([5])
array([25.])

# Lock the exponent to fit a scaled relationship >>> reg = PowerRegression(locked_params={‘b’: 2.0}) >>> reg.fit(x, y) # Only fits a

Parameters:

locked_params (dict[str, float] | None)

fit(x, y)[source]

Fit power regression model.

Args:

x: Independent variable values (must be positive) y: Dependent variable values (must be positive)

Returns:

Self for method chaining

Parameters:
  • x (ArrayLike)

  • y (ArrayLike)

Return type:

PowerRegression

predict(x)[source]

Predict y values using power model.

Args:

x: Independent variable values (must be positive)

Returns:

Predicted y values

Parameters:

x (ArrayLike)

Return type:

ndarray

equation()[source]

Return the power equation as a string.

Return type:

str

class logsuite.analysis.regression.PolynomialExponentialRegression(degree=2, locked_params=None)[source]

Bases: RegressionBase

Polynomial-Exponential regression: y = 10^(a + b*x + c*x² + … + n*x^degree)

This is an exponential function with a polynomial in the exponent. Equivalent to: log₁₀(y) = a + b*x + c*x² + … + n*x^degree

This form is particularly useful for petrophysical relationships like porosity-permeability where data spans orders of magnitude and the relationship has curvature in log-space.

Note: Only valid for positive y values.

Example:
>>> # Quadratic exponential (default degree=2)
>>> reg = PolynomialExponentialRegression(degree=2)
>>> reg.fit([0.1, 0.15, 0.2, 0.25], [0.1, 1.0, 10.0, 50.0])
>>> reg.predict([0.3])
array([150.])
>>> print(reg.equation())
y = 10^(-2.5694 + 25.2696*x - 21.0434*x²)

# Linear exponential (degree=1, same as exponential but base 10) >>> reg = PolynomialExponentialRegression(degree=1) >>> reg.fit(x, y)

# Lock specific coefficients >>> reg = PolynomialExponentialRegression(degree=2, locked_params={‘c0’: 0.0}) >>> reg.fit(x, y) # Forces constant term to 0

Parameters:
fit(x, y)[source]

Fit polynomial-exponential regression model.

Args:

x: Independent variable values y: Dependent variable values (must be positive)

Returns:

Self for method chaining

Parameters:
  • x (ArrayLike)

  • y (ArrayLike)

Return type:

PolynomialExponentialRegression

predict(x)[source]

Predict y values using polynomial-exponential model.

Args:

x: Independent variable values

Returns:

Predicted y values

Parameters:

x (ArrayLike)

Return type:

ndarray

equation()[source]

Return the polynomial-exponential equation as a string.

Return type:

str