RoPWR: Robust Piecewise Regression

1.2.0 · active · verified Thu Apr 16

RoPWR (Robust Piecewise Regression) is a Python library that implements robust piecewise regression using convex optimization techniques. It provides a flexible framework to model non-linear relationships with segments, supporting various solvers via CVXPY. The current version is 1.2.0, with releases occurring every few months, primarily driven by feature additions, improvements, and dependency updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate, fit, and predict with the `RoPWR` model. It creates a simple dataset with two linear segments and fits a `RoPWR` model with two segments. The 'Clarabel' solver is specified, which is efficient for SOCP problems.

import numpy as np
from ropwr import RoPWR

# Generate some synthetic data
np.random.seed(0)
X = np.linspace(0, 10, 100).reshape(-1, 1)
y = np.where(X < 5, 2 * X, -X + 15).flatten() + np.random.normal(0, 1, 100)

# Initialize and fit the RoPWR model with 2 segments
model = RoPWR(n_segments=2, solver='Clarabel', random_state=42)
model.fit(X, y)

# Make predictions
y_pred = model.predict(X)

print(f"Predicted y for X[0]: {y_pred[0]:.2f}")
print(f"R^2 score: {model.score(X, y):.2f}")

view raw JSON →