1
$\begingroup$

I have data for 50 patients.

This data comprises a different set of variables, of which one of them is a binary variable. For example, the presence of a given symptom (1= have the symptom, 0 = doesn't have the symptom).

I want to know what are the traits that define that a given person may develop this symptom. In order to do this, I want to assess the minimum number of variables that define the whole set of patients with a 1.

In other words, what is the combination of variables that all the patients with this symptom have in common.

I believe you can do this with random forest classifier, but I'm not sure how.

A notebook, or any kind of information on how to develop it, as well as other machine learning techniques to solve this problem would be helpful.

$\endgroup$
2
  • $\begingroup$ how many attributes (variables) do you have? are the 50 patients your whole data set or just a sample? $\endgroup$
    – 99_m4n
    Commented Jul 25, 2022 at 0:43
  • $\begingroup$ Also if you don't have too many variables you can take a look at Decision Trees, Information gain and Hunt's algorithm $\endgroup$
    – 99_m4n
    Commented Jul 25, 2022 at 0:50

1 Answer 1

0
$\begingroup$

you can use a dense layer network in Keras to predict the symptom. dense layers are very good at large feature sets for classifying.

Steps

  1. build a dataframe where each feature is a column with a 0 or 1 value and a numeric value for the symptom
      lst=[]
      for i in range(1,18):
          lst.append(i)
      for i in lst:
         df['Symptom_'+str(i)]=df['Symptom_'+str(i)].apply(lambda x: str(x).strip()) 
    
        symptoms=set(df['Symptom'])
        features=set(pd.concat([df['Feature_'+str(i)] for i in lst],axis=0))
        symptoms.discard(np.NaN)
        #print(diseases)
        encoder = LabelEncoder()
        df['Target']=encoder.fit_transform(df['Symptom'])
        y=pd.get_dummies(df['Target'])
        y_original=df['Target']
        df.drop('Target',inplace=True,axis=1)
    
        df2=pd.DataFrame(columns=features)
        #convert features to float
        for x in features:
            df2[x]=df2[x].astype(float)
        #print(df2)
        for key,item in df.iterrows():
            #print(key)
            dict={}
            for x in features:
                dict[x]=0
            df2=df2.append(dict,ignore_index=True)
            index=len(df2)
            for i in lst:
                column='Feature_'+str(i)
                value=str(item[column])
                if value != None:
                    df2.loc[index-1,value]=1
        X=df2            
        
        print(X)

    model=Sequential()
    model.add(layers.Input(shape=(len(features),), name='main_input'))
    model.add(Dense(300, activation='tanh')) 
    model.add(Dense(100, activation='tanh')) 
    model.add(Dense(64, activation='tanh')) 
    model.add(Dense(34, activation='tanh')) 
    model.add(Flatten())
    model.add(Dense(len(y.columns),activation='softmax'))
    
    print(len(X),len(y))
    X_train, X_test, y_train, y_test= train_test_split(X,y,test_size=0.3)
    
    print(X_train)
    
    model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
    
    history=model.fit(X_train,y_train, epochs=150, verbose=0)
    
    plt.plot(history.history['loss'])
    plt.title('loss accuracy')
    plt.ylabel('accuracy')
    plt.xlabel('epoch')
    plt.legend(['train', 'test'], loc='upper left')
    plt.show()
```
$\endgroup$
1
  • $\begingroup$ if you can post a dummy dataset with features and symptoms, I will run it against my classifier. $\endgroup$ Commented Jul 25, 2022 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.