function [trainedClassifier, validationAccuracy] = trainClassifier_codeletioninIDHMutantLGGnew(trainingData)
% [trainedClassifier, validationAccuracy] = trainClassifier(trainingData)
% returns a trained classifier and its accuracy. This code recreates the
% classification model trained in Classification Learner app. Use the
% generated code to automate training the same model with new data, or to
% learn how to programmatically train models.
%
%  Input:
%      trainingData: a table containing the same predictor and response
%       columns as imported into the app.
%
%  Output:
%      trainedClassifier: a struct containing the trained classifier. The
%       struct contains various fields with information about the trained
%       classifier.
%
%      trainedClassifier.predictFcn: a function to make predictions on new
%       data.
%
%      validationAccuracy: a double containing the accuracy in percent. In
%       the app, the History list displays this overall accuracy score for
%       each model.
%
% Use the code to train the model with new data. To retrain your
% classifier, call the function from the command line with your original
% data or new data as the input argument trainingData.
%
% For example, to retrain a classifier trained with the original data set
% T, enter:
%   [trainedClassifier, validationAccuracy] = trainClassifier(T)
%
% To make predictions with the returned 'trainedClassifier' on new data T2,
% use
%   yfit = trainedClassifier.predictFcn(T2)
%
% T2 must be a table containing at least the same predictor columns as used
% during training. For details, enter:
%   trainedClassifier.HowToPredict

% Auto-generated by MATLAB on 09-Apr-2018 22:25:25


% Extract predictors and response
% This code processes the data into the right shape for training the
% model.
inputTable = trainingData;
predictorNames = {'CET1_ORI_F33', 'CET1_ORI_F34', 'CET1_ORI_F39', 'CET1_ORI_F40', 'CET1_ORI_F60', 'CET1_ORI_F61', 'CET1_ORI_F65', 'CET1_ORI_F67', 'CET1_ORI_F69', 'CET1_ORI_F727', 'CET1_ORI_F807', 'CET1_LLL_F58', 'CET1_LLL_F60', 'CET1_LLL_F61', 'CET1_LLL_F65', 'CET1_LLL_F67', 'CET1_LLL_F69', 'CET1_LLH_F7', 'CET1_LLH_F11', 'CET1_LHL_F60', 'CET1_LHL_F65', 'CET1_HLL_F26', 'CET1_HLL_F27', 'CET1_HLL_F30', 'CET1_HLL_F31', 'CET1_HLL_F32', 'CET1_HLL_F33', 'CET1_HLL_F34', 'CET1_HLL_F37', 'CET1_HLL_F38', 'CET1_HLL_F39', 'CET1_HLL_F40', 'CET1_HLL_F42', 'CET1_HLH_F26', 'CET1_HLH_F27', 'CET1_HLH_F29', 'CET1_HLH_F30', 'CET1_HLH_F31', 'CET1_HLH_F32', 'CET1_HLH_F33', 'CET1_HLH_F34', 'CET1_HLH_F37', 'CET1_HLH_F38', 'CET1_HLH_F39', 'CET1_HLH_F40', 'CET1_HLH_F42', 'T2_ORI_F11', 'T2_ORI_F23', 'T2_ORI_F41', 'T2_ORI_F43', 'T2_ORI_F44', 'T2_ORI_F46', 'T2_LLL_F11', 'T2_LLL_F23', 'T2_LLL_F41', 'T2_LLL_F43', 'T2_LLL_F44', 'T2_LLL_F46', 'T2_LLL_F70', 'T2_LLH_F28', 'T2_LLH_F58', 'T2_LLH_F60', 'T2_LLH_F61', 'T2_LLH_F65', 'T2_LLH_F67', 'T2_LLH_F69', 'T2_LLH_F70', 'T2_LHH_F27', 'T2_LHH_F29', 'T2_LHH_F30', 'T2_LHH_F31', 'T2_LHH_F32', 'T2_LHH_F33', 'T2_LHH_F34', 'T2_LHH_F35', 'T2_LHH_F37', 'T2_LHH_F38', 'T2_LHH_F39', 'T2_LHH_F40', 'T2_LHH_F42', 'T2_LHH_F45', 'T2_LHH_F60', 'T2_LHH_F61', 'T2_LHH_F65', 'T2_LHH_F66', 'T2_LHH_F67', 'T2_LHH_F69', 'T2_HLL_F60', 'T2_HLL_F65', 'T2_HLL_F71', 'T2_HLH_F23', 'T2_HLH_F41', 'T2_HLH_F43', 'T2_HLH_F44', 'T2_HLH_F60', 'T2_HLH_F61', 'T2_HLH_F62', 'T2_HLH_F65', 'T2_HLH_F66', 'T2_HLH_F67', 'T2_HLH_F69', 'T2_HLH_F71', 'T2_HHL_F407', 'T2_HHH_F60', 'T2_HHH_F62', 'T2_HHH_F71', 'FLAIR_ORI_F27', 'FLAIR_ORI_F29', 'FLAIR_ORI_F30', 'FLAIR_ORI_F33', 'FLAIR_ORI_F34', 'FLAIR_ORI_F37', 'FLAIR_ORI_F38', 'FLAIR_ORI_F39', 'FLAIR_ORI_F40', 'FLAIR_ORI_F50', 'FLAIR_ORI_F547', 'FLAIR_ORI_F549', 'FLAIR_ORI_F716', 'FLAIR_ORI_F725', 'FLAIR_ORI_F727', 'FLAIR_LLL_F727', 'FLAIR_LHH_F26', 'FLAIR_LHH_F27', 'FLAIR_LHH_F29', 'FLAIR_LHH_F30', 'FLAIR_LHH_F31', 'FLAIR_LHH_F32', 'FLAIR_LHH_F33', 'FLAIR_LHH_F34', 'FLAIR_LHH_F37', 'FLAIR_LHH_F38', 'FLAIR_LHH_F39', 'FLAIR_LHH_F40', 'FLAIR_LHH_F42', 'FLAIR_HHL_F29', 'FLAIR_HHL_F30', 'FLAIR_HHL_F31', 'FLAIR_HHL_F32', 'FLAIR_HHL_F33', 'FLAIR_HHL_F34', 'FLAIR_HHL_F38', 'FLAIR_HHL_F39', 'FLAIR_HHL_F40', 'FLAIR_HHL_F42', 'FLAIR_HHL_F407', 'FLAIR_HHH_F407', 'age', 'gender'};
predictors = inputTable(:, predictorNames);
response = inputTable.codeletion;
isCategoricalPredictor = [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true];

% Train a classifier
% This code specifies all the classifier options and trains the classifier.
classificationSVM = fitcsvm(...
    predictors, ...
    response, ...
    'KernelFunction', 'polynomial', ...
    'PolynomialOrder', 2, ...
    'KernelScale', 'auto', ...
    'BoxConstraint', 1, ...
    'Standardize', true, ...
    'ClassNames', {'codel'; 'non-codel'});

% Create the result struct with predict function
predictorExtractionFcn = @(t) t(:, predictorNames);
svmPredictFcn = @(x) predict(classificationSVM, x);
trainedClassifier.predictFcn = @(x) svmPredictFcn(predictorExtractionFcn(x));

% Add additional fields to the result struct
trainedClassifier.RequiredVariables = {'CET1_ORI_F33', 'CET1_ORI_F34', 'CET1_ORI_F39', 'CET1_ORI_F40', 'CET1_ORI_F60', 'CET1_ORI_F61', 'CET1_ORI_F65', 'CET1_ORI_F67', 'CET1_ORI_F69', 'CET1_ORI_F727', 'CET1_ORI_F807', 'CET1_LLL_F58', 'CET1_LLL_F60', 'CET1_LLL_F61', 'CET1_LLL_F65', 'CET1_LLL_F67', 'CET1_LLL_F69', 'CET1_LLH_F7', 'CET1_LLH_F11', 'CET1_LHL_F60', 'CET1_LHL_F65', 'CET1_HLL_F26', 'CET1_HLL_F27', 'CET1_HLL_F30', 'CET1_HLL_F31', 'CET1_HLL_F32', 'CET1_HLL_F33', 'CET1_HLL_F34', 'CET1_HLL_F37', 'CET1_HLL_F38', 'CET1_HLL_F39', 'CET1_HLL_F40', 'CET1_HLL_F42', 'CET1_HLH_F26', 'CET1_HLH_F27', 'CET1_HLH_F29', 'CET1_HLH_F30', 'CET1_HLH_F31', 'CET1_HLH_F32', 'CET1_HLH_F33', 'CET1_HLH_F34', 'CET1_HLH_F37', 'CET1_HLH_F38', 'CET1_HLH_F39', 'CET1_HLH_F40', 'CET1_HLH_F42', 'T2_ORI_F11', 'T2_ORI_F23', 'T2_ORI_F41', 'T2_ORI_F43', 'T2_ORI_F44', 'T2_ORI_F46', 'T2_LLL_F11', 'T2_LLL_F23', 'T2_LLL_F41', 'T2_LLL_F43', 'T2_LLL_F44', 'T2_LLL_F46', 'T2_LLL_F70', 'T2_LLH_F28', 'T2_LLH_F58', 'T2_LLH_F60', 'T2_LLH_F61', 'T2_LLH_F65', 'T2_LLH_F67', 'T2_LLH_F69', 'T2_LLH_F70', 'T2_LHH_F27', 'T2_LHH_F29', 'T2_LHH_F30', 'T2_LHH_F31', 'T2_LHH_F32', 'T2_LHH_F33', 'T2_LHH_F34', 'T2_LHH_F35', 'T2_LHH_F37', 'T2_LHH_F38', 'T2_LHH_F39', 'T2_LHH_F40', 'T2_LHH_F42', 'T2_LHH_F45', 'T2_LHH_F60', 'T2_LHH_F61', 'T2_LHH_F65', 'T2_LHH_F66', 'T2_LHH_F67', 'T2_LHH_F69', 'T2_HLL_F60', 'T2_HLL_F65', 'T2_HLL_F71', 'T2_HLH_F23', 'T2_HLH_F41', 'T2_HLH_F43', 'T2_HLH_F44', 'T2_HLH_F60', 'T2_HLH_F61', 'T2_HLH_F62', 'T2_HLH_F65', 'T2_HLH_F66', 'T2_HLH_F67', 'T2_HLH_F69', 'T2_HLH_F71', 'T2_HHL_F407', 'T2_HHH_F60', 'T2_HHH_F62', 'T2_HHH_F71', 'FLAIR_ORI_F27', 'FLAIR_ORI_F29', 'FLAIR_ORI_F30', 'FLAIR_ORI_F33', 'FLAIR_ORI_F34', 'FLAIR_ORI_F37', 'FLAIR_ORI_F38', 'FLAIR_ORI_F39', 'FLAIR_ORI_F40', 'FLAIR_ORI_F50', 'FLAIR_ORI_F547', 'FLAIR_ORI_F549', 'FLAIR_ORI_F716', 'FLAIR_ORI_F725', 'FLAIR_ORI_F727', 'FLAIR_LLL_F727', 'FLAIR_LHH_F26', 'FLAIR_LHH_F27', 'FLAIR_LHH_F29', 'FLAIR_LHH_F30', 'FLAIR_LHH_F31', 'FLAIR_LHH_F32', 'FLAIR_LHH_F33', 'FLAIR_LHH_F34', 'FLAIR_LHH_F37', 'FLAIR_LHH_F38', 'FLAIR_LHH_F39', 'FLAIR_LHH_F40', 'FLAIR_LHH_F42', 'FLAIR_HHL_F29', 'FLAIR_HHL_F30', 'FLAIR_HHL_F31', 'FLAIR_HHL_F32', 'FLAIR_HHL_F33', 'FLAIR_HHL_F34', 'FLAIR_HHL_F38', 'FLAIR_HHL_F39', 'FLAIR_HHL_F40', 'FLAIR_HHL_F42', 'FLAIR_HHL_F407', 'FLAIR_HHH_F407', 'age', 'gender'};
trainedClassifier.ClassificationSVM = classificationSVM;
trainedClassifier.About = 'This struct is a trained model exported from Classification Learner R2017a.';
trainedClassifier.HowToPredict = sprintf('To make predictions on a new table, T, use: \n  yfit = c.predictFcn(T) \nreplacing ''c'' with the name of the variable that is this struct, e.g. ''trainedModel''. \n \nThe table, T, must contain the variables returned by: \n  c.RequiredVariables \nVariable formats (e.g. matrix/vector, datatype) must match the original training data. \nAdditional variables are ignored. \n \nFor more information, see <a href="matlab:helpview(fullfile(docroot, ''stats'', ''stats.map''), ''appclassification_exportmodeltoworkspace'')">How to predict using an exported model</a>.');

% Extract predictors and response
% This code processes the data into the right shape for training the
% model.
inputTable = trainingData;
predictorNames = {'CET1_ORI_F33', 'CET1_ORI_F34', 'CET1_ORI_F39', 'CET1_ORI_F40', 'CET1_ORI_F60', 'CET1_ORI_F61', 'CET1_ORI_F65', 'CET1_ORI_F67', 'CET1_ORI_F69', 'CET1_ORI_F727', 'CET1_ORI_F807', 'CET1_LLL_F58', 'CET1_LLL_F60', 'CET1_LLL_F61', 'CET1_LLL_F65', 'CET1_LLL_F67', 'CET1_LLL_F69', 'CET1_LLH_F7', 'CET1_LLH_F11', 'CET1_LHL_F60', 'CET1_LHL_F65', 'CET1_HLL_F26', 'CET1_HLL_F27', 'CET1_HLL_F30', 'CET1_HLL_F31', 'CET1_HLL_F32', 'CET1_HLL_F33', 'CET1_HLL_F34', 'CET1_HLL_F37', 'CET1_HLL_F38', 'CET1_HLL_F39', 'CET1_HLL_F40', 'CET1_HLL_F42', 'CET1_HLH_F26', 'CET1_HLH_F27', 'CET1_HLH_F29', 'CET1_HLH_F30', 'CET1_HLH_F31', 'CET1_HLH_F32', 'CET1_HLH_F33', 'CET1_HLH_F34', 'CET1_HLH_F37', 'CET1_HLH_F38', 'CET1_HLH_F39', 'CET1_HLH_F40', 'CET1_HLH_F42', 'T2_ORI_F11', 'T2_ORI_F23', 'T2_ORI_F41', 'T2_ORI_F43', 'T2_ORI_F44', 'T2_ORI_F46', 'T2_LLL_F11', 'T2_LLL_F23', 'T2_LLL_F41', 'T2_LLL_F43', 'T2_LLL_F44', 'T2_LLL_F46', 'T2_LLL_F70', 'T2_LLH_F28', 'T2_LLH_F58', 'T2_LLH_F60', 'T2_LLH_F61', 'T2_LLH_F65', 'T2_LLH_F67', 'T2_LLH_F69', 'T2_LLH_F70', 'T2_LHH_F27', 'T2_LHH_F29', 'T2_LHH_F30', 'T2_LHH_F31', 'T2_LHH_F32', 'T2_LHH_F33', 'T2_LHH_F34', 'T2_LHH_F35', 'T2_LHH_F37', 'T2_LHH_F38', 'T2_LHH_F39', 'T2_LHH_F40', 'T2_LHH_F42', 'T2_LHH_F45', 'T2_LHH_F60', 'T2_LHH_F61', 'T2_LHH_F65', 'T2_LHH_F66', 'T2_LHH_F67', 'T2_LHH_F69', 'T2_HLL_F60', 'T2_HLL_F65', 'T2_HLL_F71', 'T2_HLH_F23', 'T2_HLH_F41', 'T2_HLH_F43', 'T2_HLH_F44', 'T2_HLH_F60', 'T2_HLH_F61', 'T2_HLH_F62', 'T2_HLH_F65', 'T2_HLH_F66', 'T2_HLH_F67', 'T2_HLH_F69', 'T2_HLH_F71', 'T2_HHL_F407', 'T2_HHH_F60', 'T2_HHH_F62', 'T2_HHH_F71', 'FLAIR_ORI_F27', 'FLAIR_ORI_F29', 'FLAIR_ORI_F30', 'FLAIR_ORI_F33', 'FLAIR_ORI_F34', 'FLAIR_ORI_F37', 'FLAIR_ORI_F38', 'FLAIR_ORI_F39', 'FLAIR_ORI_F40', 'FLAIR_ORI_F50', 'FLAIR_ORI_F547', 'FLAIR_ORI_F549', 'FLAIR_ORI_F716', 'FLAIR_ORI_F725', 'FLAIR_ORI_F727', 'FLAIR_LLL_F727', 'FLAIR_LHH_F26', 'FLAIR_LHH_F27', 'FLAIR_LHH_F29', 'FLAIR_LHH_F30', 'FLAIR_LHH_F31', 'FLAIR_LHH_F32', 'FLAIR_LHH_F33', 'FLAIR_LHH_F34', 'FLAIR_LHH_F37', 'FLAIR_LHH_F38', 'FLAIR_LHH_F39', 'FLAIR_LHH_F40', 'FLAIR_LHH_F42', 'FLAIR_HHL_F29', 'FLAIR_HHL_F30', 'FLAIR_HHL_F31', 'FLAIR_HHL_F32', 'FLAIR_HHL_F33', 'FLAIR_HHL_F34', 'FLAIR_HHL_F38', 'FLAIR_HHL_F39', 'FLAIR_HHL_F40', 'FLAIR_HHL_F42', 'FLAIR_HHL_F407', 'FLAIR_HHH_F407', 'age', 'gender'};
predictors = inputTable(:, predictorNames);
response = inputTable.codeletion;
isCategoricalPredictor = [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true];

% Perform cross-validation
partitionedModel = crossval(trainedClassifier.ClassificationSVM, 'KFold', 5);

% Compute validation predictions
[validationPredictions, validationScores] = kfoldPredict(partitionedModel);

% Compute validation accuracy
validationAccuracy = 1 - kfoldLoss(partitionedModel, 'LossFun', 'ClassifError');
