當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。