Skip to main content
added 7 characters in body
Source Link
Pluviophile
  • 4.1k
  • 14
  • 32
  • 55

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

  1. build an 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()

    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()
```

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

  1. build an 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()

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

  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()
```
Source Link

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 an 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()