Skip to content

Add/hist gbc #144

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions pyprophet/scoring/classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
train_test_split,
)
from sklearn.svm import LinearSVC
from sklearn.ensemble import HistGradientBoostingClassifier

from .data_handling import Experiment

Expand Down Expand Up @@ -299,6 +300,41 @@ def set_parameters(self, classifier):
return self


class HistGBCLearner(AbstractLearner):
def __init__(self, autotune=False, threads=1):
self.classifier = None
self.importance = None
self.autotune = autotune
self.threads = threads

def tune(
self, decoy_peaks, target_peaks, use_main_score=True, cv_splits=3, n_jobs=-1
):
raise NotImplementedError(
"Hyperparameter tuning for HistGradientBoostingClassifier is not implemented."
)

def learn(self, decoy_peaks, target_peaks, use_main_score=True):
assert isinstance(decoy_peaks, Experiment)
assert isinstance(target_peaks, Experiment)

X0 = decoy_peaks.get_feature_matrix(use_main_score)
X1 = target_peaks.get_feature_matrix(use_main_score)
X = np.vstack((X0, X1))
y = np.zeros((X.shape[0],))
y[X0.shape[0] :] = 1.0

classifier = HistGradientBoostingClassifier(
random_state=42, max_iter=100, early_stopping=True, validation_fraction=0.1
)
classifier.fit(X, y)

self.classifier = classifier
# self.importance = classifier.feature_importances_

return self


class XGBLearner(AbstractLearner):
"""
Implements an XGBoost-based learner for scoring.
Expand Down