Commit 350f0b5c by simonabottani

Add RB Rep K Fold

parent 632d3432
Pipeline #954 passed with stages
in 1 minute 48 seconds
......@@ -500,3 +500,56 @@ class VB_LearningCurveRepHoldOut_DualSVM(base.MLWorkflow):
self._input.save_weights_as_nifti(weights, classifier_dir)
self._validation.save_results(self._output_dir)
class RB_RepKFold_DualSVM(base.MLWorkflow):
def __init__(self, caps_directory, subjects_visits_tsv, diagnoses_tsv, group_id, image_type, atlas,
output_dir, pvc=None, n_threads=15, n_iterations=100, test_size=0.3,
grid_search_folds=10, balanced=True, c_range=np.logspace(-6, 2, 17), splits_indices=None):
self._output_dir = output_dir
self._n_threads = n_threads
self._n_iterations = n_iterations
self._test_size = test_size
self._grid_search_folds = grid_search_folds
self._balanced = balanced
self._c_range = c_range
self._splits_indices = splits_indices
self._input = input.CAPSRegionBasedInput(caps_directory, subjects_visits_tsv, diagnoses_tsv, group_id,
image_type, atlas, pvc)
self._validation = None
self._algorithm = None
def run(self):
x = self._input.get_x()
y = self._input.get_y()
kernel = self._input.get_kernel()
self._algorithm = algorithm.DualSVMAlgorithm(kernel,
y,
balanced=self._balanced,
grid_search_folds=self._grid_search_folds,
c_range=self._c_range,
n_threads=self._n_threads)
self._validation = validation.RepeatedKFoldCV(self._algorithm)
classifier, best_params, results = self._validation.validate(y, n_iterations=self._n_iterations,
n_folds=self._n_folds, n_threads=self._n_threads)
classifier_dir = path.join(self._output_dir, 'classifier')
if not path.exists(classifier_dir):
os.makedirs(classifier_dir)
self._algorithm.save_classifier(classifier, classifier_dir)
weights = self._algorithm.save_weights(classifier, x, classifier_dir)
self._algorithm.save_parameters(best_params, classifier_dir)
self._validation.save_results(self._output_dir)
self._input.save_weights_as_nifti(weights, classifier_dir)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment