We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem: Catboost method "select_features" fails with custom metric catboost version: 1.0.3 Operating System: 20.04.3 LTS (Focal Fossa) CPU: Intel Xeon Processor (Icelake) GPU: -
import sys import numpy as np import pandas as pd import catboost print(sys.version) print('numpy', np.__version__) print('pandas', pd.__version__) print('catboost', catboost.__version__) # from https://catboost.ai/en/docs/concepts/python-usages-examples#custom-loss-function-eval-metric class LoglossMetric(object): def get_final_error(self, error, weight): return error / (weight + 1e-38) def is_max_optimal(self): return False def evaluate(self, approxes, target, weight): assert len(approxes) == 1 assert len(target) == len(approxes[0]) approx = approxes[0] error_sum = 0.0 weight_sum = 0.0 for i in range(len(approx)): e = np.exp(approx[i]) p = e / (1 + e) w = 1.0 if weight is None else weight[i] weight_sum += w error_sum += -w * (target[i] * np.log(p) + (1 - target[i]) * np.log(1 - p)) return error_sum, weight_sum data = pd.DataFrame({'A': [1, 2, 3, 4] * 100, 'B': [6, 7, 8, 9] * 100, 'target': [0, 1] * 200}) features = ['A', 'B'] train_pool = catboost.Pool(data[features], data['target']) clf = catboost.CatBoostClassifier(iterations=2, eval_metric=LoglossMetric()) clf.fit(train_pool) clf = catboost.CatBoostClassifier(iterations=2) clf.select_features(train_pool, features_for_select=features, steps=1, num_features_to_select=1) clf = catboost.CatBoostClassifier(iterations=2, eval_metric=LoglossMetric()) clf.select_features(train_pool, features_for_select=features, steps=1, num_features_to_select=1)
3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0] numpy 1.20.3 pandas 1.3.4 catboost 1.0.3 Learning rate set to 0.5 0: learn: 0.3432238 total: 379ms remaining: 379ms 1: learn: 0.1999481 total: 379ms remaining: 0us Learning rate set to 0.5 Step #1 out of 1 0: learn: 0.3432126 total: 415us remaining: 415us 1: learn: 0.1999658 total: 746us remaining: 0us Feature #0 eliminated Train final model 0: learn: 0.3432126 total: 304us remaining: 304us 1: learn: 0.1999658 total: 511us remaining: 0us Learning rate set to 0.5 Step #1 out of 1 Traceback (most recent call last): File "cb_bug2.py", line 48, in <module> clf.select_features(train_pool, features_for_select=features, steps=1, num_features_to_select=1) File "/home/asciishell/project/venv/lib/python3.8/site-packages/catboost/core.py", line 4017, in select_features summary = self._object._select_features(train_pool, test_pool, params) File "_catboost.pyx", line 5001, in _catboost._CatBoost._select_features File "_catboost.pyx", line 5015, in _catboost._CatBoost._select_features _catboost.CatBoostError: util/generic/maybe.cpp:4: TMaybe is empty
The text was updated successfully, but these errors were encountered:
[catboost] support custom metric in select features #1920
d397f11
ref:7162f0515040b67ecefded45f60d453c4d883b65
Custom eval metric is supported now in select_features.
select_features
Sorry, something went wrong.
8a0317b
No branches or pull requests
Problem: Catboost method "select_features" fails with custom metric
catboost version: 1.0.3
Operating System: 20.04.3 LTS (Focal Fossa)
CPU: Intel Xeon Processor (Icelake)
GPU: -
The text was updated successfully, but these errors were encountered: