Predict probability when model was trained in balanced dataset I have a dataset of about 1M observation and I had to predict a response that occurs only about 10.000 times (1%). 
I decided to train a random forest, but this takes a lot of time to train because the data is too large for my hardware. So I decided to take a sample, but an aleatory sample would be already too large to have a minimum quantity of response. (If  I take 10% aleatory, i would have only 1000 response)
Then I took a stratified sample. All responses and 10.000 aleatory non-responses, and trained my model in this dataset.
But now I need to rescale the probability so I have the real probability of the observation to be response.
I tried to simulate this problem with this code in R. Training a model in a balanced dataset and another one in the unbalanced data. But those models are not very correlated and I didn't find a good way to tranform the probabilities to the original unbalanced scale.


I found that for logistic regression I can do this by just changing the intercept this way:
$$ \hat{\beta_0}  =  \hat{\beta_0^*} - log(\frac{\gamma_1}{\gamma_2})$$
Where $ \gamma_1 = Pr(Z=1|Y=1)$ and $ \gamma_2 = Pr(Z=1|Y=0)$. $Z$ is the an aleatory variable indicating if the observation is in the reduced dataset.
This was found in this book (in portuguese) page 216

simulate_data <- function(n){
  X <- data.frame(matrix(runif(n*20), ncol = 20))
  list(
    X = X,
    Y = rbinom(n, size = 1, prob = apply(X, 1, sum) %>% pnorm(mean = 13)) %>% as.factor()  
  )
}

balance <- function(X, Y){
  X <- rbind(
    X[Y == "1",],
    X[Y == "0",] %>% sample_n(length(Y[Y == "1"]))
    )
  return(list(
    X = X,
    Y = as.factor(c(rep(c(1,0), each = length(Y[Y == "1"]))))
  ))
}

train <- simulate_data(100000)

library(randomForest)
m_desb <- mean(train$Y == "1")
modelo_desb <- randomForest(train$X,train$Y, ntree = 200, cutoff = c(1-m_desb, m_desb), nodesize = 30, mtry = 8)
bal <- balance(train$X, train$Y)
m_bal <- mean(bal$Y == "1")
modelo_bal <- randomForest(bal$X,bal$Y, ntree = 100, cutoff = c(1-m_bal, m_bal), nodesize = 50)


Code for plot
library(ggplot2)
data.frame(
  unbalanced = predict(modelo_desb, newdata = test$X, type = "prob")[,2],
  balanced = predict(modelo_bal, newdata = test$X, type = "prob")[,2]
) %>%
  ggplot(aes(x = balanced, y = unbalanced)) +
  geom_point(size = 0.3) +
  xlim(0,1) +
  geom_smooth() +
  geom_hline(yintercept = m_desb, linetype = "dashed") +
  geom_vline(xintercept = m_bal, linetype = "dashed")

 A: If your trained model is (very) good, the stratification should be no problem, because the forest classify the observations correctly in spite of the stratification. 
What is your hardware? If you have several cpus you can use the R-package ranger, this is probably much faster and yields the same results as randomForest. 
You can also train random forests iteratively on parts of the datasets and at the end put them together. 1 M is not too much, depending on your number and type of features you can easily train a random forest model with 50000 observations
There are also other packages like h2o, ...
And you can use AWS Amazon, ...
Maybe a simpler model than random forest (e.g. simply rule based) but trained on the whole dataset can also provide better results, than using only a part of the data. 
edit:
What you can do, is also to use the strata and sampsize argument (as a vector) in the randomForest package. There you can specify exactly the number of samples you want to have from each of the classes. And in different trees you can get completely different samples as you sample from all observations. 
