本文整理汇总了Python中catboost.CatBoostClassifier.save_model方法的典型用法代码示例。如果您正苦于以下问题:Python CatBoostClassifier.save_model方法的具体用法?Python CatBoostClassifier.save_model怎么用?Python CatBoostClassifier.save_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类catboost.CatBoostClassifier
的用法示例。
在下文中一共展示了CatBoostClassifier.save_model方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train_preprocessor
# 需要导入模块: from catboost import CatBoostClassifier [as 别名]
# 或者: from catboost.CatBoostClassifier import save_model [as 别名]
def train_preprocessor(path='.', train='train.csv'):
print('start train trash preprocessor...')
df = pd.read_csv(os.path.join(path, train))
train_data = df[:-100]
validation_data = df[-100: -50]
vectorizer = CountVectorizer()
x_train_counts = vectorizer.fit_transform(train_data.text)
x_validation_counts = vectorizer.transform(validation_data.text)
model = CatBoostClassifier(iterations=250,
train_dir=path,
logging_level='Silent',
allow_writing_files=False
)
model.fit(X=x_train_counts.toarray(),
y=train_data.status,
eval_set=(x_validation_counts.toarray(), validation_data.status),
use_best_model=True,)
model.save_model(os.path.join(path, 'trash_model'))
joblib.dump(vectorizer,os.path.join(path, 'trash_vectorizer'))
print('end train sentiment preprocessor...')
示例2: test_full_history
# 需要导入模块: from catboost import CatBoostClassifier [as 别名]
# 或者: from catboost.CatBoostClassifier import save_model [as 别名]
def test_full_history():
train_pool = Pool(TRAIN_FILE, column_description=CD_FILE)
test_pool = Pool(TEST_FILE, column_description=CD_FILE)
model = CatBoostClassifier(od_type='Iter', od_wait=20, random_seed=42, approx_on_full_history=True)
model.fit(train_pool, eval_set=test_pool)
model.save_model(OUTPUT_MODEL_PATH)
return compare_canonical_models(OUTPUT_MODEL_PATH)
示例3: test_non_ones_weight
# 需要导入模块: from catboost import CatBoostClassifier [as 别名]
# 或者: from catboost.CatBoostClassifier import save_model [as 别名]
def test_non_ones_weight():
pool = Pool(TRAIN_FILE, column_description=CD_FILE)
weight = np.arange(1, pool.num_row()+1)
pool.set_weight(weight)
model = CatBoostClassifier(iterations=2, random_seed=0)
model.fit(pool)
model.save_model(OUTPUT_MODEL_PATH)
return compare_canonical_models(OUTPUT_MODEL_PATH)
示例4: test_zero_baseline
# 需要导入模块: from catboost import CatBoostClassifier [as 别名]
# 或者: from catboost.CatBoostClassifier import save_model [as 别名]
def test_zero_baseline():
pool = Pool(TRAIN_FILE, column_description=CD_FILE)
baseline = np.zeros(pool.num_row())
pool.set_baseline(baseline)
model = CatBoostClassifier(iterations=2, random_seed=0)
model.fit(pool)
model.save_model(OUTPUT_MODEL_PATH)
return compare_canonical_models(OUTPUT_MODEL_PATH)
示例5: test_multiclass
# 需要导入模块: from catboost import CatBoostClassifier [as 别名]
# 或者: from catboost.CatBoostClassifier import save_model [as 别名]
def test_multiclass():
pool = Pool(CLOUDNESS_TRAIN_FILE, column_description=CLOUDNESS_CD_FILE)
classifier = CatBoostClassifier(iterations=2, random_seed=0, loss_function='MultiClass', thread_count=8)
classifier.fit(pool)
classifier.save_model(OUTPUT_MODEL_PATH)
new_classifier = CatBoostClassifier()
new_classifier.load_model(OUTPUT_MODEL_PATH)
pred = new_classifier.predict_proba(pool)
np.save(PREDS_PATH, np.array(pred))
return local_canonical_file(PREDS_PATH)
示例6: test_ignored_features
# 需要导入模块: from catboost import CatBoostClassifier [as 别名]
# 或者: from catboost.CatBoostClassifier import save_model [as 别名]
def test_ignored_features():
train_pool = Pool(TRAIN_FILE, column_description=CD_FILE)
test_pool = Pool(TEST_FILE, column_description=CD_FILE)
model1 = CatBoostClassifier(iterations=5, random_seed=0, ignored_features=[1, 2, 3])
model2 = CatBoostClassifier(iterations=5, random_seed=0)
model1.fit(train_pool)
model2.fit(train_pool)
predictions1 = model1.predict(test_pool)
predictions2 = model2.predict(test_pool)
assert not _check_data(predictions1, predictions2)
model1.save_model(OUTPUT_MODEL_PATH)
return compare_canonical_models(OUTPUT_MODEL_PATH)
示例7: test_fit_data
# 需要导入模块: from catboost import CatBoostClassifier [as 别名]
# 或者: from catboost.CatBoostClassifier import save_model [as 别名]
def test_fit_data():
pool = Pool(CLOUDNESS_TRAIN_FILE, column_description=CLOUDNESS_CD_FILE)
eval_pool = Pool(CLOUDNESS_TEST_FILE, column_description=CLOUDNESS_CD_FILE)
base_model = CatBoostClassifier(iterations=2, random_seed=0, loss_function="MultiClass")
base_model.fit(pool)
baseline = np.array(base_model.predict(pool, prediction_type='RawFormulaVal'))
eval_baseline = np.array(base_model.predict(eval_pool, prediction_type='RawFormulaVal'))
eval_pool.set_baseline(eval_baseline)
model = CatBoostClassifier(iterations=2, random_seed=0, loss_function="MultiClass")
data = map_cat_features(pool.get_features(), pool.get_cat_feature_indices())
model.fit(data, pool.get_label(), pool.get_cat_feature_indices(), sample_weight=np.arange(1, pool.num_row()+1), baseline=baseline, use_best_model=True, eval_set=eval_pool)
model.save_model(OUTPUT_MODEL_PATH)
return compare_canonical_models(OUTPUT_MODEL_PATH)
示例8: test_classification_ctr
# 需要导入模块: from catboost import CatBoostClassifier [as 别名]
# 或者: from catboost.CatBoostClassifier import save_model [as 别名]
def test_classification_ctr():
pool = Pool(TRAIN_FILE, column_description=CD_FILE)
model = CatBoostClassifier(iterations=5, random_seed=0, ctr_description=['Borders', 'Counter'])
model.fit(pool)
model.save_model(OUTPUT_MODEL_PATH)
return compare_canonical_models(OUTPUT_MODEL_PATH)
示例9: test_class_weights
# 需要导入模块: from catboost import CatBoostClassifier [as 别名]
# 或者: from catboost.CatBoostClassifier import save_model [as 别名]
def test_class_weights():
pool = Pool(TRAIN_FILE, column_description=CD_FILE)
model = CatBoostClassifier(iterations=5, random_seed=0, class_weights=[1, 2])
model.fit(pool)
model.save_model(OUTPUT_MODEL_PATH)
return compare_canonical_models(OUTPUT_MODEL_PATH)
示例10: test_priors
# 需要导入模块: from catboost import CatBoostClassifier [as 别名]
# 或者: from catboost.CatBoostClassifier import save_model [as 别名]
def test_priors():
pool = Pool(TRAIN_FILE, column_description=CD_FILE)
model = CatBoostClassifier(iterations=5, random_seed=0, has_time=True, ctr_description=["Borders:Prior=0:Prior=0.6:Prior=1:Prior=5", "Counter:Prior=0:Prior=0.6:Prior=1:Prior=5"])
model.fit(pool)
model.save_model(OUTPUT_MODEL_PATH)
return compare_canonical_models(OUTPUT_MODEL_PATH)
示例11: test_predict_sklearn_class
# 需要导入模块: from catboost import CatBoostClassifier [as 别名]
# 或者: from catboost.CatBoostClassifier import save_model [as 别名]
def test_predict_sklearn_class():
train_pool = Pool(TRAIN_FILE, column_description=CD_FILE)
model = CatBoostClassifier(iterations=2, random_seed=0)
model.fit(train_pool)
model.save_model(OUTPUT_MODEL_PATH)
return compare_canonical_models(OUTPUT_MODEL_PATH)