-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[WIP] Chain on decision_function or predict_proba in ClassifierChain #9316
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -435,11 +435,12 @@ class labels for each estimator in the chain. | |
Chains for Multi-label Classification", 2009. | ||
|
||
""" | ||
def __init__(self, base_estimator, order=None, cv=None, random_state=None): | ||
def __init__(self, base_estimator, order=None, cv=None, random_state=None, chain_method="predict"): | ||
self.base_estimator = base_estimator | ||
self.order = order | ||
self.cv = cv | ||
self.random_state = random_state | ||
self.chain_method = chain_method | ||
|
||
def fit(self, X, Y): | ||
"""Fit the model to data matrix X and targets Y. | ||
|
@@ -568,7 +569,12 @@ def predict_proba(self, X): | |
else: | ||
X_aug = np.hstack((X, previous_predictions)) | ||
Y_prob_chain[:, chain_idx] = estimator.predict_proba(X_aug)[:, 1] | ||
Y_pred_chain[:, chain_idx] = estimator.predict(X_aug) | ||
if self.chain_method == "predict": | ||
Y_pred_chain[:, chain_idx] = estimator.predict(X_aug) | ||
elif self.chain_method == "predict_proba": | ||
Y_pred_chain[:, chain_idx] = estimator.predict_proba(X_aug) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Predict_proba returns a 2d array There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be done in fit too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
elif self.chain_method == "decision_function": | ||
Y_pred_chain[:, chain_idx] = estimator.decision_function(X_aug) | ||
inv_order = np.empty_like(self.order_) | ||
inv_order[self.order_] = np.arange(len(self.order_)) | ||
Y_prob = Y_prob_chain[:, inv_order] | ||
|
@@ -598,7 +604,12 @@ def decision_function(self, X): | |
else: | ||
X_aug = np.hstack((X, previous_predictions)) | ||
Y_decision_chain[:, chain_idx] = estimator.decision_function(X_aug) | ||
Y_pred_chain[:, chain_idx] = estimator.predict(X_aug) | ||
if self.chain_method == "predict": | ||
Y_pred_chain[:, chain_idx] = estimator.predict(X_aug) | ||
elif self.chain_method == "predict_proba": | ||
Y_pred_chain[:, chain_idx] = estimator.predict_proba(X_aug) | ||
elif self.chain_method == "decision_function": | ||
Y_pred_chain[:, chain_idx] = estimator.decision_function(X_aug) | ||
|
||
inv_order = np.empty_like(self.order_) | ||
inv_order[self.order_] = np.arange(len(self.order_)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output of these methods may be a different shape, more than a single column.