本文整理汇总了Python中catboost.CatBoostRegressor方法的典型用法代码示例。如果您正苦于以下问题:Python catboost.CatBoostRegressor方法的具体用法?Python catboost.CatBoostRegressor怎么用?Python catboost.CatBoostRegressor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类catboost
的用法示例。
在下文中一共展示了catboost.CatBoostRegressor方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _dispatch_gbdt_class
# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostRegressor [as 别名]
def _dispatch_gbdt_class(algorithm_type: str, type_of_target: str):
is_regression = type_of_target == 'continuous'
if algorithm_type == 'lgbm':
requires_lightgbm()
from lightgbm import LGBMClassifier, LGBMRegressor
return LGBMRegressor if is_regression else LGBMClassifier
elif algorithm_type == 'cat':
requires_catboost()
from catboost import CatBoostClassifier, CatBoostRegressor
return CatBoostRegressor if is_regression else CatBoostClassifier
else:
requires_xgboost()
assert algorithm_type == 'xgb'
from xgboost import XGBClassifier, XGBRegressor
return XGBRegressor if is_regression else XGBClassifier
示例2: CatBoost_First
# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostRegressor [as 别名]
def CatBoost_First(self, data, catsign, depth=8, iterations=80000):
model = cb.CatBoostRegressor(iterations=iterations, depth=depth, learning_rate=0.8, loss_function='RMSE')
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])
# 储存
self.yanzhneg_pr.append(yanre)
self.predi.append(prer)
# 分别计算训练、验证、预测的误差
# 每计算一折后,要计算训练、验证、预测数据的误差
xx = self.RMSE(xul, data['train'][:, -1])
yy = self.RMSE(yanre, data['test'][:, -1])
pp = self.RMSE(prer, data['predict'][:, -1])
# 储存误差
self.error_dict['CatBoost'] = [xx, yy, pp]
# 验证数据集的真实输出结果
self.yanzhneg_real = data['test'][:, -1]
# 预测数据集的真实输出结果
self.preal = data['predict'][:, -1]
return print('1层中的CatBoost运行完毕')
# BPNN回归
示例3: CatBoost_First
# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostRegressor [as 别名]
def CatBoost_First(self, data, catsign, depth=8, iterations=80000):
# 存储每一折中验证数据集的预测结果
yanzhenglist = []
# 存储每一折中验证数据集的真实结果
yanzhenglist_real = []
# 存储每一折中预测数据集的预测结果
prelist = []
# 存储训练、验证、预测数据的误差
errorlsit = []
# 开始每一折的训练
for zhe in [zheshu for zheshu in data.keys() if zheshu != 'predict']:
model = cb.CatBoostRegressor(iterations=iterations, depth=depth, learning_rate=0.8, loss_function='RMSE')
model.fit(data[zhe]['train'][:, :-1], data[zhe]['train'][:, -1], cat_features=catsign)
# 注意存储验证数据集结果和预测数据集结果的不同
# 训练数据集的预测结果
xul = model.predict(data[zhe]['train'][:, :-1])
# 验证的预测结果
yanre = model.predict(data[zhe]['test'][:, :-1])
# 预测的预测结果
prer = model.predict(data['predict'][:, :-1])
yanzhenglist += list(yanre)
yanzhenglist_real += list(data[zhe]['test'][:, -1])
prelist.append(prer)
# 每计算一折后,要计算训练、验证、预测数据的误差
xx = self.RMSE(xul, data[zhe]['train'][:, -1])
yy = self.RMSE(yanre, data[zhe]['test'][:, -1])
pp = self.RMSE(prer, data['predict'][:, -1])
errorlsit.append([xx, yy, pp])
# 针对预测数据集的预测结果计算均值
meanPre = np.mean(np.array(prelist), axis=0)
# 开始结合
self.yanzhneg_pr.append(yanzhenglist)
self.yanzhneg_real = yanzhenglist_real
self.predi.append(meanPre)
self.preal = data['predict'][:, -1]
# 储存误差
self.error_dict['CatBoost'] = np.mean(np.array(errorlsit), axis=0)
return print('1层中的CatBoost运行完毕')
示例4: Train
# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostRegressor [as 别名]
def Train(data, modelcount, censhu, yanzhgdata, predata, laidex=label):
'''
:param data: 训练数据
:param modelcount: 模型的个数
:param censhu: 每个模型的树的深度
:param yanzhgdata: 用于验证的数据
:param predata: 预测的数据
:param laidex: 类别型特征的数据列号索引
:return: 当前参数下该模型的训练、验证数据的结果
'''
# 用于回归的模型
model = cb.CatBoostRegressor(iterations=modelcount, depth=censhu, learning_rate=0.8, loss_function='RMSE')
# 开始训练数据
model.fit(data[:, :-1], data[:, -1], cat_features=laidex, 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)
return train_mse, add_mse, model.predict(predata[:, :-1])
# 按照误差值从小到大排列的数据
示例5: dump
# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostRegressor [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)
示例6: load
# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostRegressor [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
示例7: catboost_regressor
# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostRegressor [as 别名]
def catboost_regressor(pandas_data, catboost_params):
return CatBoostRegressor(**catboost_params).fit(pandas_data, [1, 0])
示例8: test_catboost_regressor
# 需要导入模块: import catboost [as 别名]
# 或者: from catboost import CatBoostRegressor [as 别名]
def test_catboost_regressor(self):
X, y = make_regression(n_samples=100, n_features=4, random_state=0)
catboost_model = catboost.CatBoostRegressor(task_type='CPU', loss_function='RMSE',
n_estimators=10, verbose=0)
dump_single_regression(catboost_model)
catboost_model.fit(X.astype(numpy.float32), y)
catboost_onnx = convert_catboost(catboost_model, name='CatBoostRegression',
doc_string='test regression')
self.assertTrue(catboost_onnx is not None)
dump_data_and_model(X.astype(numpy.float32), catboost_model, catboost_onnx, basename="CatBoostReg-Dec4")