def catboost_train_model(model, trainx, trainy, cate_threshold=10): model = clone(model) cates = detect_cates_for_narrayx(trainx, cate_threshold) trainx = transform_float_to_int_for_narrayx(trainx, cates) model.fit(trainx, trainy, cates) model.cates = cates return model
def catboost_train(model, trainx, trainy, testx, cate_threshold=10, predict_proba=True, eval_testx=None, cates=None): model = catboost_train_model(model, trainx, trainy, cate_threshold, cates) if (cates is None): testx = transform_float_to_int_for_narrayx(testx, model.cates) if (eval_testx is None): return predict(model, "catboost", testx, predict_proba) else: return predict(model, "catboost", testx, predict_proba), predict(model, "catboost", eval_testx, predict_proba)
def predict(trained_model, model_name, testx, predict_proba=True): if (model_name == "lgb"): iteration = trained_model.best_iteration if (iteration <= 0): iteration = trained_model.current_iteration() if (iteration < 0): print("please set iteration, now it is {}".format(iteration)) exit(1) if (predict_proba): return trained_model.predict(testx, iteration) else: if(model_name == "catboost"): testx = transform_float_to_int_for_narrayx(testx, trained_model.cates) if (predict_proba): return trained_model.predict_proba(testx) else: return trained_model.predict(testx)
def catboost_train(model, trainx, trainy, testx, cate_threshold=10, predict_proba=True): model = catboost_train_model(model, trainx, trainy, cate_threshold) testx = transform_float_to_int_for_narrayx(testx, model.cates) return predict(model, "catboost", testx, predict_proba)