Random Forest — ML Technical Interview Questions & Answers

An ensemble of decision trees that votes on the answer.

Random Forest

  • Simple meaning: Many decision trees vote. Each tree sees a random sample of rows (and often random features). The crowd is stabler than one deep tree.
  • Picture: 100 teachers each see a shuffled photocopy of the sheet and vote pass/fail. One weird tree cannot dominate.
  • sklearn: RandomForestClassifier(n_estimators=100). feature_importances_ says which columns the forest used a lot — a hint, not proof of cause.
  • Trap: saying forest never overfits (it can, just less than one huge tree). Trap: comparing to boosting without saying bagging vs sequential errors.

Technical Interview Tip: Many trees vote. More stable than one deep tree.

Code Examples for Random Forest

Random Forest — working example

def majority_vote(labels):
    return max(set(labels), key=labels.count)

neighbors = [1, 1, 0, 1, 0]
print(majority_vote(neighbors))  # kNN-style vote

# Logistic idea: score → probability via sigmoid
def sigmoid(z):
    return 1 / (1 + 2.718281828 ** (-z))
print(round(sigmoid(0.0), 3), round(sigmoid(2.0), 3))

Random Forest — classifiers map features to labels; kNN votes neighbors; logistic uses a sigmoid probability.

How to Explain Random Forest to an Interviewer

How is a random forest built?

Many trees Random samples Vote/average

Bagging means?

Bootstrap rows for each tree