311ac284d99ea7243e0918949f3a499a7a93fab5,examples/decoding/plot_haxby_space_net.py,,,#,14
Before Change
from nilearn.image import mean_img
from nilearn.plotting import plot_stat_map
background_img = mean_img(data_files.func[0])
for penalty in ["graph-net", "tv-l1"]:
////// Fit model on train data and predict on test data ////////////////////////////////////////////
decoder = SpaceNetClassifier(memory="cache", penalty=penalty)
decoder.fit(X_train, y_train)
y_pred = decoder.predict(X_test)
accuracy = (y_pred == y_test).mean() * 100.
////// Visualization //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
print("Results")
print("=" * 80)
coef_img = decoder.coef_img_
plot_stat_map(coef_img, background_img,
title="%s: accuracy %g%%" % (penalty, accuracy),
cut_coords=(-34, -16), display_mode="yz")
coef_img.to_filename("haxby_%s_weights.nii" % penalty)
print("- %s %s" % (penalty, "-" * 60))
print("Number of train samples : %i" % condition_mask_train.sum())
print("Number of test samples : %i" % condition_mask_test.sum())
print("Classification accuracy : %g%%" % accuracy)
print("_" * 80)
plt.show()
After Change
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Now Fit SpaceNet with a TV-l1 penalty
decoder = SpaceNetClassifier(memory="cache", penalty="tv-l1")
decoder.fit(X_train, y_train)
y_pred = decoder.predict(X_test)
accuracy = (y_pred == y_test).mean() * 100.
print("TV-l1 classification accuracy : %g%%" % accuracy)
// Visualization
coef_img = decoder.coef_img_
plot_stat_map(coef_img, background_img,
title="tv-l1: accuracy %g%%" % accuracy,
cut_coords=(-34, -16), display_mode="yz")
// Save the coefficients to a nifti file
coef_img.to_filename("haxby_tv-l1_weights.nii")
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 7
Instances
Project Name: nilearn/nilearn
Commit Name: 311ac284d99ea7243e0918949f3a499a7a93fab5
Time: 2015-11-29
Author: gael.varoquaux@normalesup.org
File Name: examples/decoding/plot_haxby_space_net.py
Class Name:
Method Name:
Project Name: nilearn/nilearn
Commit Name: 49257721ec65c78965df63152b8933e9baebd4a6
Time: 2015-07-28
Author: elvis.dohmatob@inria.fr
File Name: examples/decoding/plot_poldrack_space_net.py
Class Name:
Method Name:
Project Name: nilearn/nilearn
Commit Name: 98c59811ac8ac88362b6118794b598ed92682eb7
Time: 2015-07-28
Author: elvis.dohmatob@inria.fr
File Name: examples/decoding/plot_poldrack_space_net.py
Class Name:
Method Name: