@@ -199,7 +199,7 @@ xbooster provides experimental support for CatBoost models with reduced function
199199``` python
200200import pandas as pd
201201from catboost import CatBoostClassifier, Pool
202- from xbooster.cb_constructor import CatBoostScorecardConstructor
202+ from xbooster.constructor import CatBoostScorecardConstructor
203203
204204# Load data and prepare features
205205data_path = " examples/data/test_data_01d9ab8b.csv"
@@ -231,7 +231,10 @@ model = CatBoostClassifier(
231231model.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
237240scorecard = constructor.construct_scorecard()
@@ -242,11 +245,33 @@ print(scorecard.head(3))
242245print (" \n Raw Leaf Values:" )
243246print (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
246253raw_scores = constructor.predict_score(X, method = " raw" )
247254woe_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
248265points_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
251276from sklearn.metrics import roc_auc_score
252277
@@ -458,10 +483,13 @@ Contributions are welcome! For bug reports or feature requests, please open an i
458483For 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