time_series = masker.fit_transform(fmri_filenames)
// Note how we did not specify confounds above. This is bad!
correlation_matrix = np.corrcoef(time_series.T)
// Mask the main diagonal for visualization:
np.fill_diagonal(correlation_matrix, 0)
After Change
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Compute and display a correlation matrix
from nilearn.connectome import ConnectivityMeasure
correlation_measure = ConnectivityMeasure(kind="correlation")
correlation_matrix = correlation_measure.fit_transform([time_series])[0]
// Plot the correlation matrix
import numpy as np
from matplotlib import pyplot as plt
plt.figure(figsize=(10, 10))
// Mask the main diagonal for visualization:
np.fill_diagonal(correlation_matrix, 0)
plt.imshow(correlation_matrix, interpolation="nearest", cmap="RdBu_r",
vmax=0.8, vmin=-0.8)
// Add labels and adjust margins
x_ticks = plt.xticks(range(len(labels) - 1), labels[1:], rotation=90)
y_ticks = plt.yticks(range(len(labels) - 1), labels[1:])
plt.gca().yaxis.tick_right()
plt.subplots_adjust(left=.01, bottom=.3, top=.99, right=.62)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Same thing without confounds, to stress the importance of confounds
time_series = masker.fit_transform(fmri_filenames)
// Note how we did not specify confounds above. This is bad!
correlation_matrix = correlation_measure.fit_transform([time_series])[0]
// Mask the main diagonal for visualization:
np.fill_diagonal(correlation_matrix, 0)