简体   繁体   English

使用sklearn套袋分类器预测连续值

[英]predict continuous values using sklearn bagging classifier

Can I use sklearn's BaggingClassifier to produce continuous predictions? 我可以使用sklearn的BaggingClassifier产生连续的预测吗? 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)

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. 如果您对预测分类器中类的概率感兴趣,则可以使用predict_proba方法,该方法为您提供每个类的概率。 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)

The shape of Y_pred will be [n_samples, n_classes] . Y_pred的形状将为[n_samples, n_classes]

If your Y_train values are continuous and you want to predict those continuous values (ie, you're working on a regression problem), then you can use the BaggingRegressor instead. 如果您的Y_train值是连续的并且想要预测这些连续值(即,您正在处理回归问题),则可以改用BaggingRegressor

I typically use BaggingRegressor() for continuous values, and then compare performance with RMSE. 我通常将BaggingRegressor()用于连续值,然后将性能与RMSE进行比较。 example below: 下面的例子:

from sklearn.ensemble import BaggingReressor
trees = BaggingRegressor()
trees.fit(X_train,Y_train)
scores_RMSE = math.sqrt(metrics.mean_squared_error(Y_test, trees.predict(X_test))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 sklearn:在 MaskedArray 上预测的分类器 - sklearn: Classifier to predict on a MaskedArray 装袋分类机 - Bagging Classifier 如何使用 bagging 集成 SVM 和 CNN 分类器? - How to ensemble SVM and CNN classifier using bagging? 当使用来自 sklearn.neighbors.KNeighborsClassifier 的 predict 和 kneighbors 时,KNN 分类器给出不同的结果 - KNN classifier gives different results when using predict and kneighbors from sklearn.neighbors.KNeighborsClassifier 使用Sklearn.naive_bayes.Bernoulli的朴素贝叶斯分类器; 如何使用模型进行预测? - Naive Bayes Classifier using Sklearn.naive_bayes.Bernoulli; how to use model to predict? sklearn中的分类器output值范围 - Classifier output range of values in sklearn 如何使用 skLearn 构建基线 model 以预测具有多个值的 Y - How to build Baseline model to predict Y with multiple values using skLearn 如何转换sklearn中任何分类器的predict()方法的输出? - How to convert the output of the predict() method of any classifier in sklearn? 使用 Python scikit sklearn 为最近邻 (knn) 分类器调用预测函数 - Call predict function for nearest neighbor (knn) classifier with Python scikit sklearn 如何正确重塑sklearn分类器的predict_proba的多类output? - How to correctly reshape the multiclass output of predict_proba of a sklearn classifier?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM