# How to create model for classification using SVM methods?

I have a matrix for diseases associated to their symptoms, the columns represent symptoms each row is a disease. the labels 1 and 0 in the matrix data sets represent when a disease i related to specific symptoms j in the matrix[i, j] give 1 otherwise 0 if not related. the goal of this work is to implement the SVM method for classifying disease and use symptoms to generate patients for predicting the most likely diseases. then calculating the performance of model precision, recall, and F1Score.

GM = {{{1, 1, 0, 1, 1, 0, 0} ->
"rare disease", {0, 0, 0, 0, 0, 0, 0} ->
"rare disease", {0, 0, 0, 0, 0, 0, 0} ->
"rare disease", {0, 0, 0, 0, 0, 0, 0} ->
"rare disease", {1, 1, 1, 1, 0, 1, 1} ->
"rare disease", {0, 1, 1, 1, 0, 0, 0} ->
"rare disease", {1, 1, 0, 0, 0, 0, 1} ->
"rare disease", {0, 1, 0, 0, 0, 0, 1} ->
"rare disease", {0, 0, 1, 1, 0, 0, 1} ->
"rare disease", {0, 0, 0, 0, 0, 0, 0} ->
"rare disease", {0, 0, 0, 0, 0, 0, 0} ->
"rare disease", {0, 0, 0, 0, 0, 0, 0} ->
"rare disease", {1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0} ->
"comon disease", {0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1} ->
"comon disease", {0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1} ->
"comon disease", {0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1} ->
"comon disease", {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} ->
"comon disease", {0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0} ->
"comon disease"}, {{1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1} ->
"comon disease", {0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1} ->
"comon disease", {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} ->
"comon disease", {0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1} ->
"comon disease", {1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0} ->
"comon disease", {1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0} ->
"comon disease"}}


here i tried to train and test the SVM classifier

{trainset, testset} = TakeDrop[GM, 18];
SVM = Classify[trainset, Method -> "SupportVectorMachine"]


(then i genereted new matrix for patients from evry disease in the origin dataset)

Dsymp = Select[
Table[{i, Position[GM[[i]], 1] // Flatten}, {i, 1,
Dimensions[GM][[1]]}], (#[[2]] != {}) &];


for more info, the output above represented the patients which are a sets of symptoms that are related to each disease in the matrix. i need to implement the SVM method to predict the most likely disease for each patient and test the performance ,

here i generated a random sets of 10 patients to predict the most likely diseases

Samp = Table[Random[Integer, {1, Dimensions[Dsymp][[1]]}], {i, 1, 10}];


with i knowked their disease

Thank so much you for any insight guys

• It is not very clear is this a "code request" or you want your code debugged. (The posted code does not evaluate.) Also, why "SVM"? Why not "RandomForest"? – Anton Antonov Jun 11 '19 at 22:19
• both of them if you understood the code, SVM we think it is better for classification disease after the evaluation SVM performance we will check others like NN or BN. – Ben Aawf Jun 11 '19 at 22:37
• plz check again I fixed error if you can help me to resolve this problem, I will be appreciated #Anton Antonov – Ben Aawf Jun 11 '19 at 23:03

Is this OK?
for various performance indicators,
You should post a part of actual data or similar data which reflects the actual problem structure.

Furthermore,

use symptoms to generate patients for predicting the most likely diseases.

this is the task of generative model,not SVM.isn't it?
Try with LearnDistribution

GM = {{{1, 1, 0, 1, 1, 0, 0} ->
"rare disease", {0, 0, 0, 0, 0, 0, 0} ->
"rare disease", {0, 0, 0, 0, 0, 0, 0} ->
"rare disease", {0, 0, 0, 0, 0, 0, 0} ->
"rare disease", {1, 1, 1, 1, 0, 1, 1} ->
"rare disease", {0, 1, 1, 1, 0, 0, 0} ->
"rare disease", {1, 1, 0, 0, 0, 0, 1} ->
"rare disease", {0, 1, 0, 0, 0, 0, 1} ->
"rare disease", {0, 0, 1, 1, 0, 0, 1} ->
"rare disease", {0, 0, 0, 0, 0, 0, 0} ->
"rare disease", {0, 0, 0, 0, 0, 0, 0} ->
"rare disease", {0, 0, 0, 0, 0, 0, 0} ->
"rare disease", {1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0} ->
"comon disease", {0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1} ->
"comon disease", {0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1} ->
"comon disease", {0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1} ->
"comon disease", {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} ->
"comon disease", {0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0} ->
"comon disease"}, {{1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1} ->
"comon disease", {0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1} ->
"comon disease", {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} ->
"comon disease", {0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1} ->
"comon disease", {1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0} ->
"comon disease", {1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0} ->
"comon disease"}};
trainset = GM[[1]];
testset = GM[[2]];
SVM = Classify[trainset, Method -> "SupportVectorMachine"]
SVM /@ Keys /@ testset


=>

{"rare disease", "rare disease", "rare disease", "rare disease", "rare disease", "rare disease"}