yoklainterview sim

ML Engineer Cml Trees Randomforest Internals Interview Questions

75 verified ML Engineer Cml Trees Randomforest Internals interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Cml Trees Randomforest InternalsDifficulty 1
A decision tree node holds 4 training samples: 3 of class A and 1 of class B. What is the Gini impurity of this node?
  • a0.250, because one of the four samples belongs to the minority class of the node
  • b0.375, because it is 1 minus the sum of the squared class proportions
  • c0.750, because impurity is the share of the node held by the majority class
  • d0.811, because impurity sums each class proportion times its base-2 logarithm
Explanation:Gini impurity is 1 - sum(p_k^2) over the classes present in the node. With proportions 0.75 and 0.25 this gives 1 - (0.5625 + 0.0625) = 0.375. The value 0.811 is the Shannon entropy of the same node in bits, which is what the entropy criterion would report instead.
Cml Trees Randomforest InternalsDifficulty 2
In a binary classification tree, which node composition maximizes Gini impurity, and what is that maximum?
  • aA node where one class holds about 75 percent of the samples; the maximum is 0.75
  • bA node containing a single sample, since a lone sample carries no evidence; the maximum is 1.0
  • cA node split evenly between the two classes; the maximum is 0.5
  • dA node whose two classes are in a 2-to-1 ratio; the maximum is roughly 0.44
Explanation:For two classes with proportion p, Gini is 1 - p^2 - (1-p)^2 = 2p(1-p), which peaks at p = 0.5 with value 0.5. A pure node gives 0, and any imbalance moves the value below 0.5. Node size alone does not enter the formula, only the class proportions do.
Cml Trees Randomforest InternalsDifficulty 2
A node holds 8 samples, 4 positive and 4 negative. A candidate split sends 4 samples to the left child (3 positive, 1 negative) and 4 to the right child (1 positive, 3 negative). What Gini gain does this split produce?
  • a0.125, since the parent's 0.5 drops to a weighted child impurity of 0.375
  • b0.250, since each child improves on the parent by half of its own impurity value
  • c0.500, since the parent impurity is fully removed once the node has been split
  • d0.750, since the gain adds up the impurity that each of the two children removed
Explanation:Both children have Gini 1 - (0.75^2 + 0.25^2) = 0.375, and each holds half the samples, so the weighted child impurity is also 0.375. Subtracting it from the parent's 0.5 leaves a gain of 0.125. The gain is always the parent impurity minus the sample-weighted average of the children, never a sum over children.
Cml Trees Randomforest InternalsDifficulty 2
In scikit-learn 1.6, DecisionTreeClassifier accepts criterion values "gini", "entropy" and "log_loss". How do "entropy" and "log_loss" relate to each other?
  • a"log_loss" measures the calibration error of the leaf probabilities rather than node purity
  • b"log_loss" applies entropy but weights each class by its inverse frequency in the node
  • c"log_loss" evaluates a split with cross-entropy against the parent's predicted distribution
  • dThey name the same Shannon-entropy impurity measure and build identical trees
Explanation:In scikit-learn 1.6 "log_loss" is an alias of "entropy": both compute -sum(p_k * log2(p_k)) for the node, so fitting with either name yields the same thresholds and the same impurity array. The alias exists only to align the tree criterion name with the loss vocabulary used elsewhere in the library.
Cml Trees Randomforest InternalsDifficulty 2
A node holds 6 samples whose values on one continuous feature are [1, 1, 2, 2, 5, 9]. With splitter="best", how many candidate thresholds does scikit-learn evaluate on this feature at this node?
  • a3, one midpoint between each pair of neighbouring distinct values
  • b5, one boundary between each pair of neighbouring rows after sorting
  • c6, one threshold placed exactly at each sample value in the node
  • d9, one threshold per integer step across the observed value range
Explanation:The best splitter sorts the feature and considers a threshold only between two adjacent distinct values, placing it at their midpoint, so the four distinct values 1, 2, 5 and 9 give three candidates at 1.5, 3.5 and 7.0. Repeated values cannot be separated by a threshold, which is why duplicates do not add candidates.
Cml Trees Randomforest InternalsDifficulty 2
Using scikit-learn 1.6:

X = [[1.0], [2.0], [10.0], [20.0]]
y = [0, 0, 1, 1]
clf = DecisionTreeClassifier(max_depth=1).fit(X, y)
print(clf.tree_.threshold[0])


What is printed?
  • a2.0, the largest feature value that still belongs to the negative class
  • b5.5, the arithmetic mean of the four feature values present in the node
  • c6.0, the midpoint between the two values on either side of the boundary
  • d10.0, the smallest feature value that already belongs to the positive class
Explanation:The best split separates 2.0 from 10.0, and scikit-learn stores the threshold as the midpoint of that adjacent pair, so (2.0 + 10.0) / 2 = 6.0 is printed. The split condition is X <= threshold, and any value in the open interval between the two neighbours would separate the same rows; the midpoint is chosen deterministically.

Test yourself against the 1050-question ML Engineer bank.

Start interview