'Estimate the SPoC decomposition on epochs.
Parameters
X : ndarray, shape (n_epochs, n_channels, n_times)
The data on which to estimate the SPoC.
y : array, shape (n_epochs,)
The class for each epoch.
Returns
self : instance of SPoC
Returns the modified instance.'

def fit(self, X, y):

    if (not isinstance(X, np.ndarray)):
        raise ValueError(('X    should    be    of    type    ndarray    (got    %s).' % type(X)))
    self._check_Xy(X, y)
    if (len(np.unique(y)) < 2):
        raise ValueError('y    must    have    at    least    two    distinct    values.')
    target = y.astype(np.float64)
    target -= target.mean()
    target /= target.std()
    (n_epochs, n_channels) = X.shape[:2]
    covs = np.empty((n_epochs, n_channels, n_channels))
    for (ii, epoch) in enumerate(X):
        covs[ii] = _regularized_covariance(epoch, reg=self.reg)
    C = covs.mean(0)
    Cz = np.mean((covs * target[:, np.newaxis, np.newaxis]), axis=0)
    (evals, evecs) = linalg.eigh(Cz, C)
    evals = evals.real
    evecs = evecs.real
    ix = np.argsort(np.abs(evals))[::(-1)]
    evecs = evecs[:, ix].T
    self.patterns_ = linalg.pinv(evecs).T
    self.filters_ = evecs
    pick_filters = self.filters_[:self.n_components]
    X = np.asarray([np.dot(pick_filters, epoch) for epoch in X])
    X = (X ** 2).mean(axis=(-1))
    self.mean_ = X.mean(axis=0)
    self.std_ = X.std(axis=0)
    return self
