Skip to content
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

Handled errors during validation via error_score parameter #82

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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: 27 additions & 9 deletions moabb/evaluations/evaluations.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ def score(self, clf, X, y, scoring):

le = LabelEncoder()
y = le.fit_transform(y)
acc = cross_val_score(clf, X, y, cv=cv, scoring=scoring,
n_jobs=self.n_jobs, error_score=self.error_score)
return acc.mean()
try:
acc = cross_val_score(clf, X, y, cv=cv, scoring=scoring,
n_jobs=self.n_jobs, error_score=self.error_score).mean()
except ValueError as e:
if self.error_score == 'raise':
raise e
elif self.error_score is np.nan:
acc = np.nan
return acc

def is_valid(self, dataset):
return True
Expand Down Expand Up @@ -103,11 +109,17 @@ def evaluate(self, dataset, pipelines):
cv = LeaveOneGroupOut()
for train, test in cv.split(X, y, groups):
t_start = time()
score = _fit_and_score(clone(clf), X, y, scorer, train,
test, verbose=False,
parameters=None,
fit_params=None,
error_score=self.error_score)[0]
try:
score = _fit_and_score(clone(clf), X, y, scorer, train,
test, verbose=False,
parameters=None,
fit_params=None,
error_score=self.error_score)[0]
except ValueError as e:
if self.error_score == 'raise':
raise e
elif self.error_score is np.nan:
score = np.nan
duration = time() - t_start
res = {'time': duration,
'dataset': dataset,
Expand Down Expand Up @@ -176,7 +188,13 @@ def evaluate(self, dataset, pipelines):
# we eval on each session
for session in np.unique(sessions[test]):
ix = sessions[test] == session
score = _score(model, X[test[ix]], y[test[ix]], scorer)
try:
score = _score(model, X[test[ix]], y[test[ix]], scorer)
except ValueError as e:
if self.error_score == 'raise':
raise e
elif self.error_score is np.nan:
score = np.nan

res = {'time': duration,
'dataset': dataset,
Expand Down