-
-
Notifications
You must be signed in to change notification settings - Fork 25.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add prefit to VotingClassifier #7382
Comments
hm it looks like currently we currently don't support "prefit" estimators. That's a bit surprising to me. I think the easy solution would be to add a Another option would be to check in Adding a |
you can pass cv='prefit' in CalibratedClassifierCV
If cv=prefit, the classifier must have been fit already on data.
|
Did you call fit()? |
Again, we need my memoized estimator wrapper so that there's no cost in fitting again....
We shouldn't need to clone if we're merely predicting... |
we just need to decide when it's okay to allow prefit arguments and when not. they don't really fit in very well... |
@jnothman sorry for being unclear. I meant that our |
No, not cloneable. |
Are there any plans to support already fitted models in VotingClassifier? |
#9464 and related issues consider APIs for freezing estimators within
metaestimators... But roadmap on this feature is unclear
|
Hey together, as it appears that there is a conclusion in #8370, would it be possible to add the feature of passing already fitted estimators to the VotingClassifier and VotingRegressor? If yes, @franchuterivera could jump on this feature if there is a concrete way how to implement this. In case anyone already needs this feature in the meantime, one can apply the following hack which appears to work as long as one restricts to |
As described in #7382 (comment), the quick solution is to have |
Sorry for missing that and thanks for pointing this out. We would then also ignore the LabelEncoder I guess? |
I do not think we can ignore An option would also be to pass in the |
I'd like pick this up and do a PR to implement the |
EDIT: Never mind, saw that I need to call fit on it and not just pass in already fitted models, which is how I wanted to used it. Apologies.
Looking at the voting_classifier.py
class VotingClassifier(BaseEstimator, ClassifierMixin, TransformerMixin):
"""Soft Voting/Majority Rule classifier for unfitted estimators.
....
So it looks like the initialization of self.estimators should be self.estimators_
My code:
import numpy
import sys
from collections import OrderedDict
from scipy import special, stats
from scipy.stats import f_oneway
from sklearn.utils import safe_mask
from sklearn.feature_selection import SelectKBest, f_classif, f_regression
from sklearn import svm
from sklearn.metrics import accuracy_score
from sklearn.metrics import confusion_matrix
from sklearn.grid_search import GridSearchCV
import sklearn.svm
from sklearn.feature_selection import RFE
from sklearn.cross_validation import StratifiedShuffleSplit
from sklearn.ensemble import VotingClassifier
from scipy.stats.stats import pearsonr
from DataStream import *
from Config import genders
def training2(X, y, test_X = None, test_y = None):
Actual Results
Traceback (most recent call last):
File "/u/arvie/PHD/DCCA_Experiment2/expA_SVM.py", line 165, in
my_svm = training2(apply_feature_selection(train_X, features), train_y, apply_feature_selection(test_X, features), test_y)
File "/u/arvie/PHD/DCCA_Experiment2/expA_SVM.py", line 57, in training2
print(testing(X=test_X, y=test_y, clf=eclf))
File "/u/arvie/PHD/DCCA_Experiment2/expA_SVM.py", line 116, in testing
return accuracy_score(y, clf.predict(X), normalize=True)
File "/u/arvie/.local/lib/python2.7/site-packages/sklearn/ensemble/voting_classifier.py", line 149, in predict
predictions = self.predict(X)
File "/u/arvie/.local/lib/python2.7/site-packages/sklearn/ensemble/voting_classifier.py", line 226, in predict
return np.asarray([clf.predict(X) for clf in self.estimators]).T
AttributeError: 'VotingClassifier' object has no attribute 'estimators'
Versions
import sys; print("Python", sys.version)
('Python', '2.7.6 (default, Jun 22 2015, 17:58:13) \n[GCC 4.8.2]')
('NumPy', '1.11.0')
The text was updated successfully, but these errors were encountered: