Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'-f': train_path,
'-t': test_path,
'--column-description': cd_path,
'-i': '10',
'-T': '4',
'-m': model_path,
'--use-best-model': 'false',
'--test-err-log': test_error_path
}
fit_catboost_gpu(fit_params)
eval_metric(model_path, METRIC_CHECKING_MULTICLASS_NO_WEIGHTS, test_path, cd_path, eval_error_path)
compare_metrics_with_diff(METRIC_CHECKING_MULTICLASS_NO_WEIGHTS, test_error_path, eval_error_path)
py_catboost = catboost.CatBoost()
py_catboost.load_model(model_path)
assert json.loads(py_catboost.get_metadata()['multiclass_params'])['class_to_label'] == [0, 1, 2, 3]
assert json.loads(py_catboost.get_metadata()['multiclass_params'])['class_names'] == ['a', 'b', 'c', 'd']
assert json.loads(py_catboost.get_metadata()['multiclass_params'])['classes_count'] == 0
assert json.loads(py_catboost.get_metadata()['params'])['data_processing_options']['class_names'] == ['a', 'b', 'c', 'd']
return [local_canonical_file(test_error_path)]
fit_params = {
'--loss-function': loss_function,
'--boosting-type': 'Plain',
'--classes-count': '4',
'-f': train_path,
'--column-description': cd_path,
'-i': '10',
'-T': '4',
'-m': model_path,
'--use-best-model': 'false'
}
fit_catboost_gpu(fit_params)
py_catboost = catboost.CatBoost()
py_catboost.load_model(model_path)
assert json.loads(py_catboost.get_metadata()['multiclass_params'])['class_to_label'] == [1, 2]
assert json.loads(py_catboost.get_metadata()['multiclass_params'])['classes_count'] == 4
assert json.loads(py_catboost.get_metadata()['multiclass_params'])['class_names'] == []
calc_cmd = (
CATBOOST_PATH,
'calc',
'--input-path', test_path,
'--column-description', cd_path,
'-m', model_path,
'--output-path', eval_path,
'--prediction-type', prediction_type
)
def _fit_model(pool, case, fold_id, model_path):
from catboost import CatBoost
# Learn model
make_dirs_if_not_exists(FoldModelsHandler.__MODEL_DIR)
feature_count = pool.num_col()
if "ignored_features" in case.get_params():
ignored_features = case.get_params()["ignored_features"]
if len(ignored_features) and max(ignored_features) >= feature_count:
raise CatBoostError("Error: input parameter contains feature indices wich are not available in pool: "
"{}\n "
"Check eval_feature set and ignored features options".format(ignored_features))
get_eval_logger().debug('Learn model {} on fold #{}'.format(str(case), fold_id))
cur_time = time.time()
instance = CatBoost(params=case.get_params())
instance.fit(pool)
instance.save_model(fname=model_path)
get_eval_logger().debug('Operation was done in {} seconds'.format(time.time() - cur_time))
return FoldModel(case, model_path, fold_id)
def _fit(self, tunable_params):
params = Learner._fit(self, tunable_params)
self.model = cat.CatBoost(params)
self.model.fit(self.train, eval_set=self.test, verbose_eval=True)
Args:
learn_config: dict with params or instance of CatBoost. In second case instance params will be used
objective_function:
objective_function: one of CatBoost loss functions
eval_type: Type of feature evaluate (All, SeqAdd, SeqRem)
eval_metrics: Additional metrics to calculate
thread_count: thread_count to use. If not none will override learn_config values
Returns
-------
result : Instance of EvaluationResult class
"""
features_to_eval = set(features_to_eval)
if eval_metrics is None:
eval_metrics = []
eval_metrics = eval_metrics if isinstance(eval_metrics, list) else [eval_metrics]
if isinstance(learn_config, CatBoost):
params = learn_config.get_params()
else:
params = dict(learn_config)
if loss_function is not None:
if "loss_function" in params and params["loss_function"] != loss_function:
raise CatBoostError("Loss function in params {} should be equal to feature evaluation objective "
"function {}".format(params["loss_function"], loss_function))
else:
if "loss_function" not in params:
raise CatBoostError("Provide loss function in params or as option to eval_features method")
if thread_count is not None and thread_count != -1:
params["thread_count"] = thread_count
if eval_step is None:
class_names=classes,
rounded=True,
precision=True,
filled=True,
)
)
display(SVG(graph.pipe(format="svg")))
elif isinstance(self.model, xgb.XGBModel):
return xgb.plot_tree(self.model)
elif isinstance(self.model, lgb.sklearn.LGBMModel):
return lgb.plot_tree(self.model)
elif isinstance(self.model, cb.CatBoost):
return self.model.plot_tree(tree_idx=tree_num, pool=self.pool)
elif isinstance(self.model, sklearn.ensemble.BaseEnsemble):
estimator = self.model.estimators_[tree_num]
graph = Source(
sklearn.tree.export_graphviz(
estimator,
out_file=None,
feature_names=self.features,
class_names=classes,
rounded=True,
precision=True,
filled=True,
)
)
class_names=classes,
rounded=True,
precision=True,
filled=True,
)
)
display(SVG(graph.pipe(format="svg")))
elif isinstance(self.model, xgb.XGBModel):
return xgb.plot_tree(self.model)
elif isinstance(self.model, lgb.sklearn.LGBMModel):
return lgb.plot_tree(self.model)
elif isinstance(self.model, cb.CatBoost):
return self.model.plot_tree(tree_idx=tree_num, pool=self.pool)
elif isinstance(self.model, sklearn.ensemble.BaseEnsemble):
estimator = self.model.estimators_[tree_num]
graph = Source(
sklearn.tree.export_graphviz(
estimator,
out_file=None,
feature_names=self.features,
class_names=classes,
rounded=True,
precision=True,
filled=True,
)
)