Monotone quantile regressor
Project description
About
Multiple quantiles estimation model maintaining non-crossing condition (or monotone quantile condition) using Lightgbm and XGBoost
Getting Started
- Install
pip install quantile-tree
- Run example code
import numpy as np
import plotly.graph_objects as go
from quantile_tree import QuantileRegressorLgb, QuantileRegressorXgb
if __name__ == "__main__":
sample_size = 500
alphas = [0.3, 0.4, 0.5, 0.6, 0.7]
x = np.linspace(-10, 10, sample_size)
y = np.sin(x) + np.random.uniform(-0.4, 0.4, sample_size)
x_test = np.linspace(-10, 10, sample_size)
y_test = np.sin(x_test) + np.random.uniform(-0.4, 0.4, sample_size)
monotonic_quantile_lgb = QuantileRegressorLgb(x=x, y=y_test, alphas=alphas)
lgb_params = {
"max_depth": 4,
"num_leaves": 15,
"learning_rate": 0.1,
"boosting_type": "gbdt",
}
monotonic_quantile_lgb.train(params=lgb_params)
preds_lgb = monotonic_quantile_lgb.predict(x=x_test, alphas=alphas)
lgb_fig = go.Figure(
go.Scatter(
x=x_test,
y=y_test,
name="test",
mode="markers",
)
)
for _pred, alpha in zip(preds_lgb, alphas):
lgb_fig.add_trace(
go.Scatter(x=x_test, y=_pred, name=f"{alpha}-quantile", mode="lines")
)
lgb_fig.update_layout(title="LightGBM Predictions")
lgb_fig.show()
monotonic_quantile_xgb = QuantileRegressorXgb(x=x, y=y_test, alphas=alphas)
params = {
"learning_rate": 0.65,
"max_depth": 10,
}
monotonic_quantile_xgb.train(params=params)
preds_xgb = monotonic_quantile_xgb.predict(x=x_test, alphas=alphas)
xgb_fig = go.Figure(
go.Scatter(
x=x_test,
y=y_test,
name="test",
mode="markers",
)
)
for _pred, alpha in zip(preds_xgb, alphas):
xgb_fig.add_trace(
go.Scatter(x=x_test, y=_pred, name=f"{alpha}-quantile", mode="lines")
)
xgb_fig.update_layout(title="XGBoost Predictions")
xgb_fig.show()
-
Results
-
Structure
.
├── quantile_tree
│ ├── __init__.py
│ ├── abstract.py # abstract quantile tree
│ ├── model.py # seperate train logic
│ ├── objective.py # objective ftns
│ └── utils.py # utils such as verify quantiles and preprocessing
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
quantile-tree-0.0.1.tar.gz
(4.3 kB
view hashes)
Built Distribution
Close
Hashes for quantile_tree-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa83d614bd633b90972d088246e7e3e74011525db480277863802ca79733bc66 |
|
MD5 | bd0319f9f29618995b83338121283746 |
|
BLAKE2b-256 | c9d65fa88b910f0a0bb4ef5263890311e188e254cd340965d97b969b09a6db0f |