// Compute the mean epi to be used for the background of the plotting
from nilearn.image import mean_img
background_img = mean_img(func_filenames)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Fit SpaceNet with a Graph-Net penalty
from nilearn.decoding import SpaceNetClassifier
// Fit model on train data and predict on test data
decoder = SpaceNetClassifier(memory="cache", penalty="graph-net")
decoder.fit(X_train, y_train)
y_pred = decoder.predict(X_test)
accuracy = (y_pred == y_test).mean() * 100.
print("Graph-net classification accuracy : %g%%" % accuracy)
// Visualization
from nilearn.plotting import plot_stat_map, show
coef_img = decoder.coef_img_
plot_stat_map(coef_img, background_img,
title="graph-net: accuracy %g%%" % accuracy,
cut_coords=(-34, -16), display_mode="yz")
// Save the coefficients to a nifti file
coef_img.to_filename("haxby_graph-net_weights.nii")
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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")