catboost算法python接口简单使用

早上看到一篇公众号在推xgboost、lightgbm、catboost原理比较,网上大概查了下原理及接口使用,目前只提供python、R、C/C++接口,并没有看到java接口,这个算法还算比较新颖,下面简单的用python调用去接口看看,没太多的技术含量,模型训练、保存、加载都可以看到,好像也提供service服务:关于接口参数说明可以参考


这篇文章: http://blog.csdn.net/aiirrrryee/article/details/78224232


官网提供的例子:

https://tech.yandex.com/catboost/doc/dg/concepts/installation-docpage/

简单的分类、回归例子:

import numpy as np
from  catboost  import  CatBoostClassifier,CatBoostRegressor,Pool


#####¥##################分类#################################
train_data=np.random.randint(0,100,size=(100,10))
train_label=np.random.randint(0,2,size=(100))
test_data=np.random.randint(0,100,size=(50,10))
model=CatBoostClassifier(iterations=2,depth=2,learning_rate=1,loss_function='Logloss', logging_level='Verbose')
model.fit(train_data,train_label,cat_features=[0,2,5])
preds_class=model.predict(test_data)
preds_proba=model.predict_proba(test_data)
print("class=",preds_class)
print("proba=",preds_proba)


#####¥##################回归#################################
train_data = np.random.randint(0, 100, size=(100, 10))
train_label = np.random.randint(0, 1000, size=(100))
test_data = np.random.randint(0, 100, size=(50, 10))
# initialize Pool
train_pool = Pool(train_data, train_label, cat_features=[0,2,5])
test_pool = Pool(test_data, cat_features=[0,2,5])

# specify the training parameters
model = CatBoostRegressor(iterations=2, depth=2, learning_rate=1, loss_function='RMSE')
#train the model
model.fit(train_pool)
# make the prediction using the resulting model
preds = model.predict(test_pool)
print(preds)

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值