使用sklearn套袋分类器预测连续值 [英] predict continuous values using sklearn bagging classifier

查看:201
本文介绍了使用sklearn套袋分类器预测连续值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用sklearn的 BaggingClassifier 产生连续的预测吗?有类似的包装吗?我的理解是,装袋分类器使用不同的模型预测几个分类,然后报告多数答案。似乎该算法可用于为每种分类生成概率函数,然后报告平均值。

Can I use sklearn's BaggingClassifier to produce continuous predictions? Is there a similar package? My understanding is that the bagging classifier predicts several classifications with different models, then reports the majority answer. It seems like this algorithm could be used to generate probability functions for each classification then reporting the mean value.

trees = BaggingClassifier(ExtraTreesClassifier())
trees.fit(X_train,Y_train)
Y_pred = trees.predict(X_test)


推荐答案

如果您有兴趣在预测分类器中类的概率时,可以使用 predict_proba 方法,它为您提供了每个类的概率。这是对代码的单行更改:

If you're interested in predicting probabilities for the classes in your classifier, you can use the predict_proba method, which gives you a probability for each class. It's a one-line change to your code:

trees = BaggingClassifier(ExtraTreesClassifier())
trees.fit(X_train,Y_train)
Y_pred = trees.predict_proba(X_test)

<$的形状c $ c> Y_pred 将为 [n_samples,n_classes]

如果您的 Y_train 的值是连续的,并且您要预测这些连续的值(即,您正在处理回归问题),则可以使用 BaggingRegressor 代替。

If your Y_train values are continuous and you want to predict those continuous values (i.e., you're working on a regression problem), then you can use the BaggingRegressor instead.

这篇关于使用sklearn套袋分类器预测连续值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆