The data I'm woking with consists of 3 types of data:

1- binary features: those features are either 0 or 1. I have about 6 or 7 columns. 2- cells: the values here range from 0 to 0.8 at max. Here I have 38 columns. 3- genes: genes expression. I've picked 14 genes and added them. The values here are very much different from the rest, as they range from from to 400 and even more.

What I'm currently doing, is that I split the data to train and test before running the ML pipeline, and then I scale only the genes features. I scale the test set according to the train set. Like this:

 gene_cols_train = grep("^gene_", names(train_set))
    gene_cols_test = grep("^gene_", names(test_set))
    scaled_gene_cols_train = scale(train_set[,gene_cols_train])
    scaled_gene_cols_train = round(scaled_gene_cols_train*100)/100
    train_set[,gene_cols_train] = scaled_gene_cols_train
    scaled_gene_cols_test = scale(test_set[, gene_cols_test], center = attr(scaled_gene_cols_train, "scaled:center"), 
                                  scale = attr(scaled_gene_cols_train, "scaled:scale"))
    scaled_gene_cols_test = round(scaled_gene_cols_test*100)/100
    test_set[, gene_cols_test] = scaled_gene_cols_test

My question: is scaling only the genes a good approach? combining different data sources into one is kinda new to me, and I wonder how should I scale it sense the range of values differs so much between them.

thank you!

  • $\begingroup$ Scaling only makes sense for continuous variables, binary/categorical variables cannot really be scaled. $\endgroup$ May 22 at 12:57
  • $\begingroup$ Thank you. Then what about the cells features. They are also continuous, but their range of values is very far from the genes. Should I scale all of them together? (without the binary features of course). $\endgroup$ May 22 at 16:09
  • $\begingroup$ You scale each variable independently of each other, so a variables range does not matter. $\endgroup$ May 22 at 18:08
  • $\begingroup$ @user2974951 I see, so I should scale them all together. Thanks! $\endgroup$ May 22 at 19:01

1 Answer 1


Scaling is typically do on a variable-by-variable basis:

  1. Consider the first variable.

  2. Calculate its mean and standard deviation

  3. Subtract the mean from every value, and then divide every value by the standard deviation

  4. Move to the next variable and repeat the process, then the next, then the next...

(You could also proceed by subtracting the minimum value and then dividing by the range. This puts the values in the interval $[0,1]$, while the approach given above gives variables with means of zero and variances of one. There are pros and cons to each approach.)

Consequently, it does not matter that your variables come from different sources and have different ranges of values. The whole point isi to do a kind of unit conversation for each variable to give an equivalence across the variables. In the approach given below, a scaled value of $1$ always means the value is one standard deviation above the mean, no matter the variable.


Your Answer

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

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