Example #1
0
# split original dataset into training and testing datasets
X, X_t, y, y_t = train_test_split(X, y, test_size=0.25, random_state=42)

###############################################################################
#
#   F-score
#
###############################################################################
from sklearn.feature_selection import f_classif
f_values, p_values = f_classif(X, y)
p_values = -np.log10(p_values)
p_values[np.isnan(p_values)] = 0
p_values[p_values > 10] = 10
p_unmasked = masking.unmask(p_values, mask)
plot_haxby(p_unmasked, bg_img, 'F-score', slice=29)

# save statistical map as nifti image
img = nibabel.Nifti1Image(p_unmasked, np.eye(4))
img.to_filename('output_stats_f_classif.nii.gz')

###############################################################################
#                                                                             #
#   SVC                                                                       #
#                                                                             #
###############################################################################
# Define the estimator
from sklearn.svm import SVC
clf = SVC(kernel='linear', C=0.01)

# ### Dimension reduction #####################################################
Example #2
0
X, X_t, y, y_t = train_test_split(
    X, y, test_size=0.4, random_state=42
    )

###############################################################################
#
#   F-score
#
###############################################################################
from sklearn.feature_selection import f_classif
f_values, p_values = f_classif(X, y)
p_values = -np.log10(p_values)
p_values[np.isnan(p_values)] = 0
p_values[p_values > 10] = 10
p_unmasked = masking.unmask(p_values, mask)
plot_haxby(p_unmasked, mean_img, 'F-score')

# save statistical map as nifti image
img = nibabel.Nifti1Image(p_unmasked, np.eye(4))
img.to_filename('output_stats_f_classif.nii.gz')

###############################################################################
#                                                                             #
#   SVC                                                                       #
#                                                                             #
###############################################################################
# Define the estimator
from sklearn.svm import SVC
clf = SVC(kernel='linear', C=0.01)

# ### Dimension reduction #####################################################
Example #3
0
# split original dataset into training and testing datasets
X, X_t, y, y_t = train_test_split(X, y, test_size=0.4, random_state=42)

###############################################################################
#
#   F-score
#
###############################################################################
from sklearn.feature_selection import f_classif
f_values, p_values = f_classif(X, y)
p_values = -np.log10(p_values)
p_values[np.isnan(p_values)] = 0
p_values[p_values > 10] = 10
p_unmasked = masking.unmask(p_values, mask)
plot_haxby(p_unmasked, mean_img, 'F-score')

# save statistical map as nifti image
img = nibabel.Nifti1Image(p_unmasked, np.eye(4))
img.to_filename('output_stats_f_classif.nii.gz')

###############################################################################
#                                                                             #
#   SVC                                                                       #
#                                                                             #
###############################################################################
# Define the estimator
from sklearn.svm import SVC
clf = SVC(kernel='linear', C=0.01)

# ### Dimension reduction #####################################################
Example #4
0
X, X_t, y, y_t = train_test_split(
    X, y, test_size=0.25, random_state=42
    )

###############################################################################
#
#   F-score
#
###############################################################################
from sklearn.feature_selection import f_classif
f_values, p_values = f_classif(X, y)
p_values = -np.log10(p_values)
p_values[np.isnan(p_values)] = 0
p_values[p_values > 10] = 10
p_unmasked = masking.unmask(p_values, mask)
plot_haxby(p_unmasked, bg_img, 'F-score')

# save statistical map as nifti image
img = nibabel.Nifti1Image(p_unmasked, np.eye(4))
img.to_filename('output_stats_f_classif.nii.gz')

###############################################################################
#                                                                             #
#   SVC                                                                       #
#                                                                             #
###############################################################################
# Define the estimator
from sklearn.svm import SVC
clf = SVC(kernel='linear', C=0.01)

# ### Dimension reduction #####################################################
Example #5
0
import numpy as np

# ### Look at the discriminating weights
coef = clf.coef_
# reverse feature selection
coef = feature_extraction.inverse_transform(coef)

# reverse masking
coef = masking.unmask(coef[0], mask)

# # We use a masked array so that the voxels at '-1' are displayed
# # transparently
act = np.ma.masked_array(coef, coef == 0)


plot_haxby(act, mean_img, 'PCA')

# save statistical map as nifti image
img = nibabel.Nifti1Image(act, np.eye(4))
img.to_filename('output_stats.nii.gz')

# ### Visualisation (PCA) #####################################################

Z = feature_extraction.transform(X)
C = feature_extraction.transform(X_t)

# plot data in 2D (i.e. plot two main components)
import matplotlib.pyplot as plt
for i in range(len(Z)):
    if y[i] == 1:
        marker = '^'
# split original dataset into training and testing datasets
X, X_t, y, y_t = train_test_split(X, y, test_size=0.4, random_state=42)

###############################################################################
#
#   F-score
#
###############################################################################
from sklearn.feature_selection import f_classif

f_values, p_values = f_classif(X, y)
p_values = -np.log10(p_values)
p_values[np.isnan(p_values)] = 0
p_values[p_values > 10] = 10
p_unmasked = masking.unmask(p_values, mask)
plot_haxby(p_unmasked, mean_img, "F-score")

# save statistical map as nifti image
img = nibabel.Nifti1Image(p_unmasked, np.eye(4))
img.to_filename("output_stats_f_classif.nii.gz")

###############################################################################
#                                                                             #
#   SVC                                                                       #
#                                                                             #
###############################################################################
# Define the estimator
from sklearn.svm import SVC

clf = SVC(kernel="linear", C=0.01)
Example #7
0
# split original dataset into training and testing datasets
X, X_t, y, y_t = train_test_split(X, y, test_size=0.25, random_state=42)

###############################################################################
#
#   F-score
#
###############################################################################
from sklearn.feature_selection import f_classif
f_values, p_values = f_classif(X, y)
p_values = -np.log10(p_values)
p_values[np.isnan(p_values)] = 0
p_values[p_values > 10] = 10
p_unmasked = masking.unmask(p_values, mask)
plot_haxby(p_unmasked, bg_img, 'F-score')

# save statistical map as nifti image
img = nibabel.Nifti1Image(p_unmasked, np.eye(4))
img.to_filename('output_stats_f_classif.nii.gz')

###############################################################################
#                                                                             #
#   SVC                                                                       #
#                                                                             #
###############################################################################
# Define the estimator
from sklearn.svm import SVC
clf = SVC(kernel='linear', C=0.01)

# ### Dimension reduction #####################################################
Example #8
0
X, X_t, y, y_t = train_test_split(
    X, y, test_size=0.25, random_state=42
    )

###############################################################################
#
#   F-score
#
###############################################################################
from sklearn.feature_selection import f_classif
f_values, p_values = f_classif(X, y)
p_values = -np.log10(p_values)
p_values[np.isnan(p_values)] = 0
p_values[p_values > 10] = 10
p_unmasked = masking.unmask(p_values, mask)
plot_haxby(p_unmasked, bg_img, 'F-score', slice=29)

# save statistical map as nifti image
img = nibabel.Nifti1Image(p_unmasked, np.eye(4))
img.to_filename('output_stats_f_classif.nii.gz')

###############################################################################
#                                                                             #
#   SVC                                                                       #
#                                                                             #
###############################################################################
# Define the estimator
from sklearn.svm import SVC
clf = SVC(kernel='linear', C=0.01)

# ### Dimension reduction #####################################################