本文整理匯總了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")