当前位置: 首页>>代码示例>>Python>>正文


Python catboost.CatBoostClassifier方法代码示例

本文整理汇总了Python中catboost.CatBoostClassifier方法的典型用法代码示例。如果您正苦于以下问题:Python catboost.CatBoostClassifier方法的具体用法?Python catboost.CatBoostClassifier怎么用?Python catboost.CatBoostClassifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在catboost的用法示例。


在下文中一共展示了catboost.CatBoostClassifier方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Train

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def Train(data, modelcount, censhu, yanzhgdata, predata, cat=data.catind):
    model = cb.CatBoostClassifier(iterations=modelcount, depth=censhu, learning_rate=0.5, loss_function='Logloss',
                                  logging_level='Verbose')

    model.fit(data[:, :-1], data[:, -1], cat_features=cat, eval_set=(yanzhgdata[:, :-1], yanzhgdata[:, -1]))
    # 给出训练数据的分数
    train_mse = model.score(data[:, :-1], data[:, -1])

    # 给出验证数据的分数
    add_mse = model.score(yanzhgdata[:, :-1], yanzhgdata[:, -1])
    print(train_mse, add_mse)
    # 输出预测数据的预测值
    preout = model.predict(predata[:, :-1])
    return train_mse, add_mse, preout

# 最终确定组合的函数 
开发者ID:Anfany,项目名称:Machine-Learning-for-Beginner-by-Python3,代码行数:18,代码来源:CatBoost_Classify_adult.py

示例2: test_cv_cat_df

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def test_cv_cat_df():
    X, y = make_classification_df(n_samples=1024, n_num_features=20, n_cat_features=1, class_sep=0.98, random_state=0)
    X, _ = autoprep_gbdt('cat', X, None)
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=0)

    models = [CatBoostClassifier(n_estimators=300) for _ in range(5)]

    pred_oof, pred_test, scores, importance = cross_validate(models, X_train, y_train, X_test, cv=5,
                                                             eval_func=roc_auc_score,
                                                             fit_params={'cat_features': ['cat_0']})

    print(scores)
    assert len(scores) == 5 + 1
    assert scores[-1] >= 0.85  # overall roc_auc
    assert roc_auc_score(y_train, pred_oof) == scores[-1]
    assert roc_auc_score(y_test, pred_test) >= 0.85  # test roc_auc
    assert roc_auc_score(y_test, models[0].predict_proba(X_test)[:, 1]) >= 0.85  # make sure models are trained
    assert len(importance) == 5
    assert list(importance[0].columns) == ['feature', 'importance']
    assert len(importance[0]) == 20 + 1
    assert models[0].tree_count_ < 300  # making sure early stopping worked 
开发者ID:nyanp,项目名称:nyaggle,代码行数:23,代码来源:test_cross_validate.py

示例3: __init__

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def __init__(self):
        self._models = dict()
        try:
            import sklearn.ensemble
            self._models['RandomForestClassifier'] = sklearn.ensemble.RandomForestClassifier
        except ImportError:
            pass

        try:
            import xgboost
            self._models['XGBClassifier'] = xgboost.XGBClassifier
        except ImportError:
            pass

        try:
            import lightgbm
            self._models['LGBMClassifier'] = lightgbm.LGBMClassifier
        except ImportError:
            pass

        try:
            import catboost
            self._models['CatBoostClassifier'] = catboost.CatBoostClassifier
        except ImportError:
            pass 
开发者ID:m3dev,项目名称:redshells,代码行数:27,代码来源:prediction_model_factory.py

示例4: fit

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def fit(self, X, y, sample_weight=None, eval_set=None, sample_weight_eval_set=None, **kwargs):
        lb = LabelEncoder()
        lb.fit(self.labels)
        y = lb.transform(y)
        orig_cols = list(X.names)
        XX = X.to_pandas()
        params = {
            'train_dir': user_dir(),
            'allow_writing_files': False,
            'thread_count': 10,
            # 'loss_function': 'Logloss'
        }
        from catboost import CatBoostClassifier
        model = CatBoostClassifier(**params)
        model.fit(XX, y=y, sample_weight=sample_weight, verbose=False,
                  cat_features=list(X[:, [str, int]].names))  # Amazon specific, also no early stopping

        # must always set best_iterations
        self.set_model_properties(model=model,
                                  features=orig_cols,
                                  importances=model.feature_importances_,
                                  iterations=0) 
开发者ID:h2oai,项目名称:driverlessai-recipes,代码行数:24,代码来源:amazon.py

示例5: test_catboost_bin_classifier

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def test_catboost_bin_classifier(self):
        import onnxruntime
        from distutils.version import StrictVersion

        if StrictVersion(onnxruntime.__version__) >= StrictVersion('1.3.0'):
            X, y = make_classification(n_samples=100, n_features=4, random_state=0)
            catboost_model = catboost.CatBoostClassifier(task_type='CPU', loss_function='CrossEntropy',
                                                         n_estimators=10, verbose=0)
            catboost_model.fit(X.astype(numpy.float32), y)

            catboost_onnx = convert_catboost(catboost_model, name='CatBoostBinClassification',
                                             doc_string='test binary classification')
            self.assertTrue(catboost_onnx is not None)
            dump_data_and_model(X.astype(numpy.float32), catboost_model, catboost_onnx, basename="CatBoostBinClass")

        else:
            warnings.warn('Converted CatBoost models for binary classification work with onnxruntime version 1.3.0 or '
                          'a newer one') 
开发者ID:onnx,项目名称:onnxmltools,代码行数:20,代码来源:test_CatBoost_converter.py

示例6: __init__

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def __init__(self, **kwargs):
        super().__init__()
        self.estimator = ctb.CatBoostClassifier(**kwargs) 
开发者ID:minerva-ml,项目名称:steppy-toolkit,代码行数:5,代码来源:models.py

示例7: CatBoost_First

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def CatBoost_First(self, data, catsign, depth=5, iterations=200):

        model = cb.CatBoostClassifier(iterations=iterations, depth=depth, learning_rate=0.5,
                                      loss_function='Logloss', logging_level='Verbose')

        model.fit(data['train'][:, :-1], data['train'][:, -1], cat_features=catsign)
        # 注意存储验证数据集结果和预测数据集结果的不同
        # 训练数据集的预测结果
        xul = model.predict(data['train'][:, :-1])
        # 验证的预测结果
        yanre = model.predict(data['test'][:, :-1])
        # 预测的预测结果
        prer = model.predict(data['predict'][:, :-1])

        # 每计算一折后,要计算训练、验证、预测数据的误差
        xx = self.F1(xul, data['train'][:, -1])

        yy = self.F1(yanre, data['test'][:, -1])

        pp = self.F1(prer, data['predict'][:, -1])

        # 开始结合
        self.yanzhneg_pr.append(yanre)
        self.yanzhneg_real = data['test'][:, -1]
        self.predi.append(prer)
        self.preal = data['predict'][:, -1]

        # 存储误差
        self.error_dict['CatBoost'] = [xx, yy, pp]

        return print('1层中的CatBoost运行完毕') 
开发者ID:Anfany,项目名称:Machine-Learning-for-Beginner-by-Python3,代码行数:33,代码来源:Blending_Classify_adult.py

示例8: __init__

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def __init__(self, target_labels, *args, **kwargs):
        self.target_labels = target_labels
        self.n_classes = len(target_labels)
        self.models = [CatBoostClassifier(*args, **kwargs) for _ in range(self.n_classes)] 
开发者ID:Donskov7,项目名称:toxic_comments,代码行数:6,代码来源:models.py

示例9: dump

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def dump(self, model) -> ArtifactCollection:
        """
        Dumps `catboost.CatBoostClassifier` or `catboost.CatBoostRegressor` instance to :class:`.LocalFileBlob` and
        creates :class:`.ArtifactCollection` from it

        :return: context manager with :class:`~ebonite.core.objects.ArtifactCollection`
        """
        model_file = tempfile.mktemp()
        try:
            model.save_model(model_file)
            yield Blobs({self._get_model_file_name(model): LocalFileBlob(model_file)})
        finally:
            os.remove(model_file) 
开发者ID:zyfra,项目名称:ebonite,代码行数:15,代码来源:model.py

示例10: _get_model_file_name

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def _get_model_file_name(self, model):
        if isinstance(model, CatBoostClassifier):
            return self.classifier_file_name
        return self.regressor_file_name 
开发者ID:zyfra,项目名称:ebonite,代码行数:6,代码来源:model.py

示例11: load

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def load(self, path):
        """
        Loads `catboost.CatBoostClassifier` or `catboost.CatBoostRegressor` instance from path

        :param path: path to load from
        """
        if os.path.exists(os.path.join(path, self.classifier_file_name)):
            model_type = CatBoostClassifier
        else:
            model_type = CatBoostRegressor

        model = model_type()
        model.load_model(os.path.join(path, self._get_model_file_name(model)))
        return model 
开发者ID:zyfra,项目名称:ebonite,代码行数:16,代码来源:model.py

示例12: _exposed_methods_mapping

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def _exposed_methods_mapping(self):
        ret = {
            'predict': 'predict'
        }
        if isinstance(self.model, CatBoostClassifier):
            ret['predict_proba'] = 'predict_proba'
        return ret 
开发者ID:zyfra,项目名称:ebonite,代码行数:9,代码来源:model.py

示例13: catboost_classifier

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def catboost_classifier(pandas_data, catboost_params):
    return CatBoostClassifier(**catboost_params).fit(pandas_data, [1, 0]) 
开发者ID:zyfra,项目名称:ebonite,代码行数:4,代码来源:test_model.py

示例14: test_serialization_final_fallback

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def test_serialization_final_fallback(ray_start_regular):
    pytest.importorskip("catboost")
    # This test will only run when "catboost" is installed.
    from catboost import CatBoostClassifier

    model = CatBoostClassifier(
        iterations=2,
        depth=2,
        learning_rate=1,
        loss_function="Logloss",
        logging_level="Verbose")

    reconstructed_model = ray.get(ray.put(model))
    assert set(model.get_params().items()) == set(
        reconstructed_model.get_params().items()) 
开发者ID:ray-project,项目名称:ray,代码行数:17,代码来源:test_serialization.py

示例15: __init__

# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostClassifier [as 别名]
def __init__(self, **kwargs):
        self.estimator = ctb.CatBoostClassifier(**kwargs) 
开发者ID:minerva-ml,项目名称:open-solution-home-credit,代码行数:4,代码来源:models.py


注:本文中的catboost.CatBoostClassifier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。