本文整理汇总了Python中pyriemann.classification.MDM.fit方法的典型用法代码示例。如果您正苦于以下问题:Python MDM.fit方法的具体用法?Python MDM.fit怎么用?Python MDM.fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyriemann.classification.MDM
的用法示例。
在下文中一共展示了MDM.fit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_MDM_predict
# 需要导入模块: from pyriemann.classification import MDM [as 别名]
# 或者: from pyriemann.classification.MDM import fit [as 别名]
def test_MDM_predict():
"""Test prediction of MDM"""
covset = generate_cov(100,3)
labels = np.array([0,1]).repeat(50)
mdm = MDM(metric='riemann')
mdm.fit(covset,labels)
mdm.predict(covset)
示例2: test_MDM_transform
# 需要导入模块: from pyriemann.classification import MDM [as 别名]
# 或者: from pyriemann.classification.MDM import fit [as 别名]
def test_MDM_transform():
"""Test transform of MDM"""
covset = generate_cov(100,3)
labels = np.array([0,1]).repeat(50)
mdm = MDM(metric='riemann')
mdm.fit(covset,labels)
mdm.transform(covset)
示例3: test_MDM_predict
# 需要导入模块: from pyriemann.classification import MDM [as 别名]
# 或者: from pyriemann.classification.MDM import fit [as 别名]
def test_MDM_predict():
"""Test prediction of MDM"""
covset = generate_cov(100, 3)
labels = np.array([0, 1]).repeat(50)
mdm = MDM(metric='riemann')
mdm.fit(covset, labels)
mdm.predict(covset)
# test fit_predict
mdm = MDM(metric='riemann')
mdm.fit_predict(covset, labels)
# test transform
mdm.transform(covset)
# predict proba
mdm.predict_proba(covset)
# test n_jobs
mdm = MDM(metric='riemann', n_jobs=2)
mdm.fit(covset, labels)
mdm.predict(covset)
示例4: DistanceCalculatorAlex
# 需要导入模块: from pyriemann.classification import MDM [as 别名]
# 或者: from pyriemann.classification.MDM import fit [as 别名]
class DistanceCalculatorAlex(BaseEstimator, TransformerMixin):
"""Distance Calulator Based on MDM."""
def __init__(self, metric_mean='logeuclid', metric_dist=['riemann'],
n_jobs=7, subsample=10):
"""Init."""
self.metric_mean = metric_mean
self.metric_dist = metric_dist
self.n_jobs = n_jobs
self.subsample = subsample
def fit(self, X, y):
"""Fit."""
self.mdm = MDM(metric=self.metric_mean, n_jobs=self.n_jobs)
labels = np.squeeze(create_sequence(y.T)[::self.subsample])
self.mdm.fit(X, labels)
return self
def transform(self, X, y=None):
"""Transform."""
feattr = []
for metric in self.metric_dist:
self.mdm.metric_dist = metric
feat = self.mdm.transform(X)
# substract distance of the class 0
feat = feat[:, 1:] - np.atleast_2d(feat[:, 0]).T
feattr.append(feat)
feattr = np.concatenate(feattr, axis=1)
feattr[np.isnan(feattr)] = 0
return feattr
def fit_transform(self, X, y):
"""Fit and transform."""
self.fit(X, y)
return self.transform(X)
示例5: max
# 需要导入模块: from pyriemann.classification import MDM [as 别名]
# 或者: from pyriemann.classification.MDM import fit [as 别名]
for train_idx, test_idx in cv:
y_train, y_test = labels[train_idx], labels[test_idx]
clf.fit(epochs_data[train_idx], y_train)
scores.append(clf.score(epochs_data[test_idx], y_test))
# Printing the results
class_balance = np.mean(labels == labels[0])
class_balance = max(class_balance, 1. - class_balance)
print("Classification accuracy: %f / Chance level: %f" % (np.mean(scores),
class_balance))
# spatial patterns
xd = XdawnCovariances(n_components)
Cov = xd.fit_transform(epochs_data,labels)
evoked.data = xd.Xd._patterns.T
evoked.times = np.arange(evoked.data.shape[0])
evoked.plot_topomap(times=[0, 1, n_components, n_components+1], ch_type='grad',
colorbar=False, size=1.5)
# prototyped covariance matrices
mdm = MDM()
mdm.fit(Cov,labels)
fig,axe = plt.subplots(1,2)
axe[0].matshow(mdm.covmeans[0])
axe[0].set_title('Class 1 covariance matrix')
axe[1].matshow(mdm.covmeans[1])
axe[1].set_title('Class 2 covariance matrix')
plt.show()
示例6: Pipeline
# 需要导入模块: from pyriemann.classification import MDM [as 别名]
# 或者: from pyriemann.classification.MDM import fit [as 别名]
clf = Pipeline([('CSP', csp), ('LDA', lda)])
scores = cross_val_score(clf, epochs_data_train, labels, cv=cv, n_jobs=1)
# Printing the results
class_balance = np.mean(labels == labels[0])
class_balance = max(class_balance, 1. - class_balance)
print("CSP + LDA Classification accuracy: %f / Chance level: %f" %
(np.mean(scores), class_balance))
###############################################################################
# Display MDM centroid
mdm = MDM()
mdm.fit(cov_data_train, labels)
fig, axes = plt.subplots(1, 2, figsize=[8, 4])
ch_names = [ch.replace('.', '') for ch in epochs.ch_names]
df = pd.DataFrame(data=mdm.covmeans[0], index=ch_names, columns=ch_names)
g = sns.heatmap(df, ax=axes[0], square=True, cbar=False, xticklabels=2,
yticklabels=2)
g.set_title('Mean covariance - hands')
df = pd.DataFrame(data=mdm.covmeans[1], index=ch_names, columns=ch_names)
g = sns.heatmap(df, ax=axes[1], square=True, cbar=False, xticklabels=2,
yticklabels=2)
plt.xticks(rotation='vertical')
plt.yticks(rotation='horizontal')
g.set_title('Mean covariance - feets')
示例7: ERPDistance
# 需要导入模块: from pyriemann.classification import MDM [as 别名]
# 或者: from pyriemann.classification.MDM import fit [as 别名]
class ERPDistance(BaseEstimator, TransformerMixin):
"""ERP distance cov estimator.
This transformer estimates Riemannian distance for ERP covariance matrices.
After estimation of special form ERP covariance matrices using the ERP
transformer, a MDM [1] algorithm is used to compute Riemannian distance.
References:
[1] A. Barachant, S. Bonnet, M. Congedo and C. Jutten, "Multiclass
Brain-Computer Interface Classification by Riemannian Geometry," in IEEE
Transactions on Biomedical Engineering, vol. 59, no. 4, p. 920-928, 2012
"""
def __init__(self, window=500, nfilters=3, subsample=1, metric='riemann',
n_jobs=1):
"""Init."""
self.window = window
self.nfilters = nfilters
self.subsample = subsample
self.metric = metric
self.n_jobs = n_jobs
self._fitted = False
def fit(self, X, y):
"""fit."""
# Create ERP and get cov mat
self.ERP = ERP(self.window, self.nfilters, self.subsample)
train_cov = self.ERP.fit_transform(X, y)
labels_train = self.ERP.labels_train
# Add rest epochs
rest_cov = self._get_rest_cov(X, y)
train_cov = np.concatenate((train_cov, rest_cov), axis=0)
labels_train = np.concatenate((labels_train, [0] * len(rest_cov)))
# fit MDM
self.MDM = MDM(metric=self.metric, n_jobs=self.n_jobs)
self.MDM.fit(train_cov, labels_train)
self._fitted = True
return self
def transform(self, X, y=None):
"""Transform."""
test_cov = self.ERP.transform(X)
dist = self.MDM.transform(test_cov)
dist = dist[:, 1:] - np.atleast_2d(dist[:, 0]).T
return dist
def update_subsample(self, old_sub, new_sub):
"""update subsampling."""
if self._fitted:
self.ERP.update_subsample(old_sub, new_sub)
def _get_rest_cov(self, X, y):
"""Sample rest epochs from data and compute the cov mat."""
ix = np.where(np.diff(y[:, 0]) == 1)[0]
rest = []
offset = - self.window
for i in ix:
start = i + offset - self.window
stop = i + offset
rest.append(self.ERP.erp_cov(X[slice(start, stop)].T))
return np.array(rest)