Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/fcma/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

def example_of_aggregating_sim_matrix(raw_data, labels, num_subjects, num_epochs_per_subj):
# aggregate the kernel matrix to save memory
svm_clf = svm.SVC(kernel='precomputed', shrinking=False, C=1)
svm_clf = svm.SVC(kernel='precomputed', shrinking=False, C=1, gamma='auto')
clf = Classifier(svm_clf, num_processed_voxels=1000, epochs_per_subj=num_epochs_per_subj)
rearranged_data = raw_data[num_epochs_per_subj:] + raw_data[0:num_epochs_per_subj]
rearranged_labels = labels[num_epochs_per_subj:] + labels[0:num_epochs_per_subj]
Expand All @@ -54,7 +54,7 @@ def example_of_aggregating_sim_matrix(raw_data, labels, num_subjects, num_epochs

def example_of_cross_validation_with_detailed_info(raw_data, labels, num_subjects, num_epochs_per_subj):
# no shrinking, set C=1
svm_clf = svm.SVC(kernel='precomputed', shrinking=False, C=1)
svm_clf = svm.SVC(kernel='precomputed', shrinking=False, C=1, gamma='auto')
#logit_clf = LogisticRegression()
clf = Classifier(svm_clf, epochs_per_subj=num_epochs_per_subj)
# doing leave-one-subject-out cross validation
Expand Down Expand Up @@ -86,7 +86,7 @@ def example_of_cross_validation_using_model_selection(raw_data, labels, num_subj
# for self-correlation, i.e. correlation between the same data matrix.

# no shrinking, set C=1
svm_clf = svm.SVC(kernel='precomputed', shrinking=False, C=1)
svm_clf = svm.SVC(kernel='precomputed', shrinking=False, C=1, gamma='auto')
#logit_clf = LogisticRegression()
clf = Classifier(svm_clf, epochs_per_subj=num_epochs_per_subj)
# doing leave-one-subject-out cross validation
Expand All @@ -104,7 +104,7 @@ def example_of_cross_validation_using_model_selection(raw_data, labels, num_subj

def example_of_correlating_two_components(raw_data, raw_data2, labels, num_subjects, num_epochs_per_subj):
# aggregate the kernel matrix to save memory
svm_clf = svm.SVC(kernel='precomputed', shrinking=False, C=1)
svm_clf = svm.SVC(kernel='precomputed', shrinking=False, C=1, gamma='auto')
clf = Classifier(svm_clf, epochs_per_subj=num_epochs_per_subj)
num_training_samples=num_epochs_per_subj*(num_subjects-1)
clf.fit(list(zip(raw_data[0:num_training_samples], raw_data2[0:num_training_samples])),
Expand All @@ -127,7 +127,7 @@ def example_of_correlating_two_components(raw_data, raw_data2, labels, num_subje
def example_of_correlating_two_components_aggregating_sim_matrix(raw_data, raw_data2, labels,
num_subjects, num_epochs_per_subj):
# aggregate the kernel matrix to save memory
svm_clf = svm.SVC(kernel='precomputed', shrinking=False, C=1)
svm_clf = svm.SVC(kernel='precomputed', shrinking=False, C=1, gamma='auto')
clf = Classifier(svm_clf, num_processed_voxels=1000, epochs_per_subj=num_epochs_per_subj)
num_training_samples=num_epochs_per_subj*(num_subjects-1)
clf.fit(list(zip(raw_data, raw_data2)), labels,
Expand Down
2 changes: 1 addition & 1 deletion examples/fcma/mvpa_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
# transpose data to facilitate training and prediction
processed_data = processed_data.T

clf = svm.SVC(kernel='linear', shrinking=False, C=1)
clf = svm.SVC(kernel='linear', shrinking=False, C=1, gamma='auto')
# doing leave-one-subject-out cross validation
for i in range(num_subjects):
leave_start = i * num_epochs_per_subj
Expand Down
2 changes: 1 addition & 1 deletion examples/fcma/mvpa_voxel_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
# create a Searchlight object
sl = Searchlight(sl_rad=1)
mvs = MVPAVoxelSelector(data, mask, labels, num_subjs, sl)
clf = svm.SVC(kernel='linear', shrinking=False, C=1)
clf = svm.SVC(kernel='linear', shrinking=False, C=1, gamma='auto')
# only rank 0 has meaningful return values
score_volume, results = mvs.run(clf)
# this output is just for result checking
Expand Down
2 changes: 1 addition & 1 deletion examples/fcma/voxel_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
# if providing two masks, just append raw_data2 as the last input argument
#vs = VoxelSelector(labels, epochs_per_subj, num_subjs, raw_data, raw_data2=raw_data2)
# for cross validation, use SVM with precomputed kernel
clf = svm.SVC(kernel='precomputed', shrinking=False, C=10)
clf = svm.SVC(kernel='precomputed', shrinking=False, C=10, gamma='auto')
results = vs.run(clf)
# this output is just for result checking
if MPI.COMM_WORLD.Get_rank()==0:
Expand Down
6 changes: 3 additions & 3 deletions examples/funcalign/srm_image_prediction_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
" train_data[:, start_index:end_index] = image_data_shared[train_subjects[train_subject]]\n",
"\n",
" # Train a Nu-SVM classifier using scikit learn\n",
" classifier = NuSVC(nu=0.5, kernel='linear')\n",
" classifier = NuSVC(nu=0.5, kernel='linear', gamma='auto')\n",
" classifier = classifier.fit(train_data.T, train_labels)\n",
"\n",
" # Predict on the test data\n",
Expand Down Expand Up @@ -393,7 +393,7 @@
" train_data[:, start_index:end_index] = image_data_shared[train_subjects[train_subject]]\n",
"\n",
" # Train a Nu-SVM classifier using scikit learn\n",
" classifier = NuSVC(nu=0.5, kernel='linear')\n",
" classifier = NuSVC(nu=0.5, kernel='linear', gamma='auto')\n",
" classifier = classifier.fit(train_data.T, train_labels)\n",
"\n",
" # Predict on the test data\n",
Expand Down Expand Up @@ -448,4 +448,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
4 changes: 2 additions & 2 deletions examples/funcalign/srm_image_prediction_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def plot_confusion_matrix(cm, title="Confusion Matrix"):
train_data[:, start_index:end_index] = image_data_shared[train_subjects[train_subject]]

# Train a Nu-SVM classifier using scikit learn
classifier = NuSVC(nu=0.5, kernel='linear')
classifier = NuSVC(nu=0.5, kernel='linear', gamma='auto')
classifier = classifier.fit(train_data.T, train_labels)

# Predict on the test data
Expand Down Expand Up @@ -153,7 +153,7 @@ def plot_confusion_matrix(cm, title="Confusion Matrix"):
train_data[:, start_index:end_index] = image_data_shared[train_subjects[train_subject]]

# Train a Nu-SVM classifier using scikit learn
classifier = NuSVC(nu=0.5, kernel='linear')
classifier = NuSVC(nu=0.5, kernel='linear', gamma='auto')
classifier = classifier.fit(train_data.T, train_labels)

# Predict on the test data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def plot_confusion_matrix(cm, title="Confusion Matrix"):
train_data[:, start_index:end_index] = image_data_shared[train_subjects[train_subject]]

# Train a Nu-SVM classifier using scikit learn
classifier = NuSVC(nu=0.5, kernel='linear')
classifier = NuSVC(nu=0.5, kernel='linear', gamma='auto')
classifier = classifier.fit(train_data.T, train_labels)

# Predict on the test data
Expand Down
2 changes: 1 addition & 1 deletion examples/searchlight/example_searchlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
def sfn(l, msk, myrad, bcast_var):
import sklearn.svm
import sklearn.model_selection
classifier = sklearn.svm.SVC()
classifier = sklearn.svm.SVC(gamma='auto')
data = l[0][msk,:].T
return np.mean(sklearn.model_selection.cross_val_score(classifier, data, bcast_var,n_jobs=1))

Expand Down
2 changes: 1 addition & 1 deletion examples/utils/fmrisim_multivariate_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9040,7 +9040,7 @@
"X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(\n",
" input_mat, input_labels, test_size=0.2, random_state=0)\n",
"\n",
"clf = sklearn.svm.SVC(kernel='linear', C=1).fit(X_train, y_train)\n",
"clf = sklearn.svm.SVC(kernel='linear', C=1, gamma='auto').fit(X_train, y_train)\n",
"\n",
"score = clf.score(X_test, y_test)\n",
"print('Classification accuracy between condition A and B: %0.3f' % score)"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def finalize_options(self):
'nitime',
# https://github.com/numpy/numpy/issues/14189
'numpy!=1.17.*',
'scikit-learn[alldeps]>=0.18,<0.22',
'scikit-learn[alldeps]>=0.18',
# See https://github.com/scipy/scipy/pull/8082
'scipy!=1.0.0',
'statsmodels',
Expand Down
4 changes: 2 additions & 2 deletions tests/fcma/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_classification():
# 5 subjects, 4 epochs per subject
epochs_per_subj = 4
# svm
svm_clf = svm.SVC(kernel='precomputed', shrinking=False, C=1)
svm_clf = svm.SVC(kernel='precomputed', shrinking=False, C=1, gamma='auto')
training_data = fake_raw_data[0:12]
clf = Classifier(svm_clf, epochs_per_subj=epochs_per_subj)
clf.fit(list(zip(training_data, training_data)), labels[0:12])
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_classification_with_two_components():
# 5 subjects, 4 epochs per subject
epochs_per_subj = 4
# svm
svm_clf = svm.SVC(kernel='precomputed', shrinking=False, C=1)
svm_clf = svm.SVC(kernel='precomputed', shrinking=False, C=1, gamma='auto')
training_data = fake_raw_data[0: 12]
training_data2 = fake_raw_data2[0: 12]
clf = Classifier(svm_clf, epochs_per_subj=epochs_per_subj)
Expand Down
2 changes: 1 addition & 1 deletion tests/fcma/test_mvpa_voxel_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_mvpa_voxel_selection():
mvs = MVPAVoxelSelector(data, mask, labels, 2, sl)
# for cross validation, use SVM with precomputed kernel

clf = svm.SVC(kernel='rbf', C=10)
clf = svm.SVC(kernel='rbf', C=10, gamma='auto')
result_volume, results = mvs.run(clf)
if MPI.COMM_WORLD.Get_rank() == 0:
output = []
Expand Down
4 changes: 2 additions & 2 deletions tests/fcma/test_voxel_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_voxel_selection():
'within-subject normalization does not provide correct results'
# for cross validation, use SVM with precomputed kernel
# no shrinking, set C=1
clf = svm.SVC(kernel='precomputed', shrinking=False, C=1)
clf = svm.SVC(kernel='precomputed', shrinking=False, C=1, gamma='auto')
results = vs.run(clf)
if MPI.COMM_WORLD.Get_rank() == 0:
output = [None] * len(results)
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_voxel_selection_with_two_masks():
raw_data2=fake_raw_data2, voxel_unit=1)
# for cross validation, use SVM with precomputed kernel
# no shrinking, set C=1
clf = svm.SVC(kernel='precomputed', shrinking=False, C=1)
clf = svm.SVC(kernel='precomputed', shrinking=False, C=1, gamma='auto')
results = vs.run(clf)
if MPI.COMM_WORLD.Get_rank() == 0:
output = [None] * len(results)
Expand Down