Closed SvdvBui closed 4 years ago
I reviewed your code and believe I have found the issue. If you consult the constructor documentation with ?mRMR.data
you will see that:
data
: is expected to be a data frame with samples and features respectively organized as rows and columns. The columns have to be of type :numeric, ordered factor, Surv and respectively interpreted as :continuous, discrete and survival variables.
Given that Response is being passed as a column to the constructor, it interprets this to mean the response is a categorical predictor. Instead this column should be passed to the strata
parameter, which:
is expected to be a vector of type :ordered factor with the strata associated to the samples provided in data.
Please try this updated code and get back to me if it here if it has resolved the issue:
library(caret)
library(mRMRe)
data <- read.csv("home/RNA_seq.csv", row.names=1, sep=";", stringsAsFactors=FALSE)
data <- data.frame(t(data))
data[,1] <- factor(data[,1])
data[,1] <- ordered(data[,1], levels = c("0", "1"))
features_select <- list()
r <- 5 # 5-cross-validation
t <- 3 # 5-cross-validation done 3 times
for (j in 1:t){
for (i in 1:r){
#5-cross-validation
train.index <- createFolds(factor(data$Response), k = 5, list = TRUE, returnTrain = TRUE)
datatrain <- data[train.index[[i]],]
datatest <- data[-train.index[[i]],]
#Feature selection
data.mrmre.train <- mRMR.data(data=datatrain[,-1], strata = datatrain[,1])
res.fs.mrmr <- mRMR.classic(data=data.mrmre.train, target_indices=1, feature_count=25)
selected.features.mrmre <- mRMRe::solutions(res.fs.mrmr)
features_select[[((j-1)*r+i)]] <- res.fs.mrmr@feature_names[unlist(selected.features.mrmre)]
print(features_select[[((j-1)*r+i)]])
print(res.fs.mrmr)
}
}
Thank you so much! That works now! Sorry for bothering you with my stupid question but I didn't find by myself the solution. Thanks again!
Hello, I have a question about your code, I am making a selection of features, and I really like your idea with the cross validation, but I have a question about the test database, I do not see it in the code part, I want to know please the utility of repartition of the database in test and train, can you explain me more please. Thank you very much.
I reviewed your code and believe I have found the issue. If you consult the constructor documentation with
?mRMR.data
you will see that:
data
: is expected to be a data frame with samples and features respectively organized as rows and columns. The columns have to be of type :numeric, ordered factor, Surv and respectively interpreted as :continuous, discrete and survival variables.Given that Response is being passed as a column to the constructor, it interprets this to mean the response is a categorical predictor. Instead this column should be passed to the
strata
parameter, which:is expected to be a vector of type :ordered factor with the strata associated to the samples provided in data.
Please try this updated code and get back to me if it here if it has resolved the issue:
library(caret) library(mRMRe) data <- read.csv("home/RNA_seq.csv", row.names=1, sep=";", stringsAsFactors=FALSE) data <- data.frame(t(data)) data[,1] <- factor(data[,1]) data[,1] <- ordered(data[,1], levels = c("0", "1")) features_select <- list() r <- 5 # 5-cross-validation t <- 3 # 5-cross-validation done 3 times for (j in 1:t){ for (i in 1:r){ #5-cross-validation train.index <- createFolds(factor(data$Response), k = 5, list = TRUE, returnTrain = TRUE) datatrain <- data[train.index[[i]],] datatest <- data[-train.index[[i]],] #Feature selection data.mrmre.train <- mRMR.data(data=datatrain[,-1], strata = datatrain[,1]) res.fs.mrmr <- mRMR.classic(data=data.mrmre.train, target_indices=1, feature_count=25) selected.features.mrmre <- mRMRe::solutions(res.fs.mrmr) features_select[[((j-1)*r+i)]] <- res.fs.mrmr@feature_names[unlist(selected.features.mrmre)] print(features_select[[((j-1)*r+i)]]) print(res.fs.mrmr) } }
Hi there! I am trying to use the mRMR.ensemble function with bootstrap method for feature selection. I stumbled on this problem, where my dependent variable (set using the argument target_indices) is selected as solution at every bootstrap. Strangely, it is always selected as last one and repeated until the fixed number of features to select is reached feature_count. I thought that I was creating the data object in a wrong way so I tried the above solution, which consists in removing the dependent variable from argument "data" and giving it in input as "strata" in the function mRmR.data(). However, I do not get the sense of calling the function mRMR.esemble (or mRMR.classic as above) using the option target_indices=1, since in this was the target is not my dependent variable anymore but the first dependent variable in the dataset. This is because in the above mentioned solution:
data.mrmre.train <- mRMR.data(data=datatrain[,-1], strata = datatrain[,1])
the argument data do not actually contains the dependent variable of interest anymore. In this sense, the mRMR is selecting the set of variables that has maximum relevance and minimum redundancy with respect to an independent variable.
Am I missing something?
Thank you in advance :)
I am a bit puzzled by this solution. I have two queries, although the second may be a style thingy.
1) If I understand correctly, in mRMR.data(data=datatrain[,-1], strata = datatrain[,1]), the response variable is allocated the strata slot, rather than part of the _featurenames slot as in the OP's code. However in _mRMR.classic(data=data.mrmre.train, target_indices=1, featurecount=25), the variable _targetindices=1 would surely not point to the required response, but to one of the other features. Is that right? How should _targetindices be used when the response is in the strata slot and no longer in the _featurenames slot?
2) Both the OP's code and the solution code have createFolds in the inner loop. Doesn't that mean the folds are created anew within each inner loop iteration with issues arising about test fold uniqueness/orthogonality. (This might be what's intended....). It seems to me having createFolds in the outer loop overcomes this. Even better(?) define createMultiFolds outside the loops, and access within. Just a thought.
Thanks, Dave
Hello,
I have a data frame "data" with 60 rows (=samples) and 20228 columns where the first column is my target variable (an ordered factor : 0 or 1) and the other columns are my features (=numeric). I want to do a feature selection with mRMRe in a loop corresponding to a 5-cross-validation that I do 3 times. I select every time 25 features. Here is the problematic part of my code :
My problem is that sometimes my target variable called "Response"(=column 1 of "data") is selected by mRMRe as a feature. When this is the case, my target variable "Response" is always selected from feature 2 up to the number requested (here 25). For example :
Here is the output of the function mRMR.classic() corresponding to the 2 features sets above.
This doesn't appear every time for the same value of i and j into the loop. Do you have an idea where is the problem ?
Thank you in advance !