I have successfully built a a sequential model to stratify different organs of some genomic data that I have, and this works really well and with a high accuracy too. However, this is also time series data and I would like to understand relationships between different variables in the data and I would like to incorporate these to see what genes drive different relationships over time. I am not sure therefore that this becomes a classification or regression problem at this point. The code for the model is below:
The code to generate the multi-class classification is as follows:
Normcountsonehot <- data.frame(to_categorical(Normcountsall$Age, 7), to_categorical(Normcountsall$Organ, 13), to_categorical(Normcountsall$Sex, 4), Normcountsall[,1:5078]) The resulting matrix is time points as rows and genes as columns. Genes contain the values we would like to extract information from. ind <- sample(2, nrow(Normcountsonehot), replace=TRUE, prob = c(0.7,0.3)) training <- Normcountsonehot[ind==1, 25:5098] # includes all independent variables test <- Normcountsonehot[ind==2, 25:5098] *scale test and training* trainingtarget <- Normcountsonehot[ind==1, c(8:20)] testtarget <- Normcountsonehot[ind==2, c(8:20)] The above splits the one-hot encoded data into the organs variable only (and not any of the others (sex, Age)
Sequential model is then:
model1 <- keras_model_sequential() model1 %>% layer_dense(units=5078, activation = 'relu', input_shape = 5074) %>% layer_dropout(0.4)%>% layer_dense(units = 64, activation = "relu") %>% layer_dropout(0.2) %>% layer_dense(units=13, activation = "softmax") model1 %>% keras::compile(loss='categorical_crossentropy', optimizer='adam', metrics='accuracy') history1 <- model1%>% fit(as.matrix(training1), # input, the first independent variables as.matrix(trainingtarget), # input, Metadata epoch=20, batch=32, validation_split = 0.2) model1%>% keras::evaluate(test1,as.matrix(testtarget)) confusion matrix etc...
This classifies just one variable very nicely
If I now add this line of code to include variables such Age and Sex:
trainingtarget <- Normcountsonehot[ind==1, c(1:24)]
and change the input in the model to:
model1 %>% layer_dense(units=5078, activation = 'relu', input_shape = 7+13+4 5078) %>% .... *last layer* layer_dense(units=7+13+4, activation = "softmax")
The train accuracy falls to basically 0 and Val-acc is constantly 0.
While I am trying to understand the relationships between these different variables to then find weights that drive these relationships, I am not sure that this is now classification problem (or the input is completely wrong). Should I remove softmax to make it a regression problem. If so, what is my last layer unit number? and what will it be training on:
again the objective would be to understand the relationships between all of the variables and see if genes change according to this. One of the variables which I have not mentioned is dependent on the type of organs.. and therefore I would like to see how the weights change when the algorithm is specifically looking for these patterns with all variables in mind. i.e... some genes may go down over time because organs x,y and z have a certain property defined by the variable, while these may be completely unchanged in other organs because they do not possess such properties... It's this kind of pattern recognition I am interested in.
Any help about how to edit the code above to address this question would be much appreciated! Also note, I will be trying different models too, but just starting with a sequential!