'Score Epochs.
Estimate scores across trials by comparing the prediction estimated for
each trial to its true value.
Calls ``predict()`` if it has not been already.
.. note::
The function updates the ``scorer_``, ``scores_``, and
``y_true_`` attributes.
.. note::
If ``predict_mode`` is \'mean-prediction\', ``score_mode`` is
automatically set to \'mean-sample-wise\'.
Parameters
epochs : instance of Epochs | None, optional
The epochs. Can be similar to fitted epochs or not.
If None, it needs to rely on the predictions ``y_pred_``
generated with ``predict()``.
y : list | ndarray, shape (n_epochs,) | None, optional
True values to be compared with the predictions ``y_pred_``
generated with ``predict()`` via ``scorer_``.
If None and ``predict_mode``==\'cross-validation\' y = ``y_train_``.
Returns
scores : list of lists of float
The scores estimated by ``scorer_`` at each training time and each
testing time (e.g. mean accuracy of ``predict(X)``). Note that the
number of testing times per training time need not be regular;
else, np.shape(scores) = (n_train_time, n_test_time). If
``score_mode`` is \'fold-wise\', np.shape(scores) = (n_train_time,
n_test_time, n_folds).'

def score(self, epochs=None, y=None):

    import sklearn.metrics
    from sklearn.base import is_classifier
    from sklearn.metrics import accuracy_score, mean_squared_error
    if check_version('sklearn', '0.17'):
        from sklearn.base import is_regressor
    else:
        def is_regressor(clf):
            return False
    if (epochs is not None):
        self.predict(epochs)
    elif (not hasattr(self, 'y_pred_')):
        raise RuntimeError('Please    predict()    epochs    first    or    pass    epochs    to    score()')
    if (self.score_mode not in ('fold-wise', 'mean-fold-wise', 'mean-sample-wise')):
        raise ValueError(("score_mode    must    be    'fold-wise',    'mean-fold-wise'    or    'mean-sample-wise'.    Got    %s    instead'" % self.score_mode))
    score_mode = self.score_mode
    if ((self.predict_mode == 'mean-prediction') and (self.score_mode != 'mean-sample-wise')):
        warn(("score_mode    changed    from    %s    set    to    'mean-sample-wise'    because    predict_mode    is    'mean-prediction'." % self.score_mode))
        score_mode = 'mean-sample-wise'
    self.scorer_ = self.scorer
    if (self.scorer_ is None):
        if (self.predict_method == 'predict'):
            if is_classifier(self.clf):
                self.scorer_ = accuracy_score
            elif is_regressor(self.clf):
                self.scorer_ = mean_squared_error
    elif isinstance(self.scorer_, str):
        if hasattr(sklearn.metrics, ('%s_score' % self.scorer_)):
            self.scorer_ = getattr(sklearn.metrics, ('%s_score' % self.scorer_))
        else:
            raise KeyError("{0}    scorer    Doesn't    appear    to    be    valid    a    scikit-learn    scorer.".format(self.scorer_))
    if (not self.scorer_):
        raise ValueError(('Could    not    find    a    scoring    metric    for    clf=%s        and    predict_method=%s.    Manually    define    scorer.' % (self.clf, self.predict_method)))
    if (y is None):
        if (self.predict_mode == 'cross-validation'):
            y = self.y_train_
        elif (epochs is not None):
            y = epochs.events[:, 2]
        else:
            raise RuntimeError('y    is    undefined    because    predict_mode="mean-prediction"    and    epochs    are    missing.    You    need    to    explicitly    specify    y.')
        if (not np.all((np.unique(y) == np.unique(self.y_train_)))):
            raise ValueError('Classes    (y)    passed    differ    from    classes    used    for    training.    Please    explicitly    pass    your    y    for    scoring.')
    elif isinstance(y, list):
        y = np.array(y)
    for att in ['scores_', 'y_true_']:
        if hasattr(self, att):
            delattr(self, att)
    self.y_true_ = y
    n_jobs = min(len(self.y_pred_[0][0]), check_n_jobs(self.n_jobs))
    (parallel, p_func, n_jobs) = parallel_func(_score_slices, n_jobs)
    n_estimators = len(self.train_times_['slices'])
    n_chunks = min(n_estimators, n_jobs)
    chunks = np.array_split(range(len(self.train_times_['slices'])), n_chunks)
    scores = parallel((p_func(self.y_true_, [self.y_pred_[train] for train in chunk], self.scorer_, score_mode, self._cv_splits) for chunk in chunks))
    self.scores_ = np.array([score for chunk in scores for score in chunk])
    return self.scores_
