Skip to content

Commit 4c6bd80

Browse files
committed
release-v0.2.5
1 parent a928d5e commit 4c6bd80

14 files changed

Lines changed: 852 additions & 605 deletions

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ __pycache__
66
.pytest_cache
77
.mypy_cache
88
*.pyc
9+
*.pkl
910
*.pyo
1011
*.pyd
1112
.venv
@@ -14,5 +15,9 @@ __pycache__
1415
catboost_info
1516
.catboost_info
1617
.vscode
18+
dist
19+
xbooster.egg-info
1720
tmp
18-
python-workspace.code-workspace
21+
python-workspace.code-workspace
22+
examples/*.sql
23+
examples/*.py

README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ xbooster provides experimental support for CatBoost models with reduced function
199199
```python
200200
import pandas as pd
201201
from catboost import CatBoostClassifier, Pool
202-
from xbooster.cb_constructor import CatBoostScorecardConstructor
202+
from xbooster.constructor import CatBoostScorecardConstructor
203203

204204
# Load data and prepare features
205205
data_path = "examples/data/test_data_01d9ab8b.csv"
@@ -231,7 +231,10 @@ model = CatBoostClassifier(
231231
model.fit(pool)
232232

233233
# Create and fit the scorecard constructor
234-
constructor = CatBoostScorecardConstructor(model, pool)
234+
constructor = CatBoostScorecardConstructor(model, pool) # use_woe=False is the default, using raw LeafValue
235+
236+
# Alternatively, to use WOE values instead of raw leaf values:
237+
# constructor = CatBoostScorecardConstructor(model, pool, use_woe=True)
235238

236239
# Construct the scorecard
237240
scorecard = constructor.construct_scorecard()
@@ -242,11 +245,33 @@ print(scorecard.head(3))
242245
print("\nRaw Leaf Values:")
243246
print(scorecard[["Tree", "LeafIndex", "LeafValue", "WOE"]].head(10))
244247

245-
# Make predictions using different methods
248+
# Make predictions using different methods - Do this BEFORE creating points
249+
# Original CatBoost predictions
250+
cb_preds = model.predict(X, prediction_type="RawFormulaVal")
251+
252+
# Get raw scores and WOE scores
246253
raw_scores = constructor.predict_score(X, method="raw")
247254
woe_scores = constructor.predict_score(X, method="woe")
255+
256+
# Now create points for the scorecard
257+
scorecard_with_points = constructor.create_points(
258+
pdo=50,
259+
target_points=600,
260+
target_odds=19,
261+
precision_points=0
262+
)
263+
264+
# Calculate points-based scores
248265
points_scores = constructor.predict_score(X, method="pdo")
249266

267+
# Even after creating points, raw and WOE scores remain consistent
268+
# This is because the constructor maintains the original mappings
269+
new_raw_scores = constructor.predict_score(X, method="raw")
270+
new_woe_scores = constructor.predict_score(X, method="woe")
271+
272+
# Verify that raw scores still match CatBoost predictions
273+
np.testing.assert_allclose(new_raw_scores, cb_preds, rtol=1e-2, atol=1e-2)
274+
250275
# Calculate Gini scores
251276
from sklearn.metrics import roc_auc_score
252277

@@ -458,10 +483,13 @@ Contributions are welcome! For bug reports or feature requests, please open an i
458483
For code contributions, please open a pull request.
459484

460485
## Version
461-
Current version: 0.2.4
486+
Current version: 0.2.5
462487

463488
## Changelog
464489

490+
### [0.2.5] - 2025-04-19
491+
- Minor changes in `catboost_wrapper.py` and `cb_constructor.py` to improve the scorecard generation.
492+
465493
### [0.2.4] - 2025-04-18
466494
- Changed the build distribution in pyproject.toml.
467495

0 commit comments

Comments
 (0)