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:
ABCBase class for all regression types.
- 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:
- 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:
- 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:
- 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:
- get_locked_params()[source]¶
Get currently locked parameters.
- Returns:
Dictionary of locked parameter names and values
- 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
- get_plot_data(x_range=None, num_points=100)[source]¶
Get x and y data for plotting the regression line.
- Parameters:
- 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:
RegressionBaseLinear 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
- 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:
- class logsuite.analysis.regression.LogarithmicRegression(locked_params=None)[source]¶
Bases:
RegressionBaseLogarithmic 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
- 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:
- class logsuite.analysis.regression.ExponentialRegression(locked_params=None)[source]¶
Bases:
RegressionBaseExponential 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
- 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:
- class logsuite.analysis.regression.PolynomialRegression(degree=2, locked_params=None)[source]¶
Bases:
RegressionBasePolynomial 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
- 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:
- class logsuite.analysis.regression.PowerRegression(locked_params=None)[source]¶
Bases:
RegressionBasePower 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
- 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:
- class logsuite.analysis.regression.PolynomialExponentialRegression(degree=2, locked_params=None)[source]¶
Bases:
RegressionBasePolynomial-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
- 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: