← Goldman Sachs Interview Insights
The gini function itself took me maybe two minutes.
Start by clearly defining Gini impurity and the weighted Gini impurity for a split, then outline an efficient algorithm that sorts feature values and evaluates candidate thresholds. Emphasize computational complexity and practical optimizations like sorting once per feature and using cumulative sums.
Pro tip: Mention that for large datasets, you can avoid sorting by using histogram-based binning, which is common in production systems like XGBoost and LightGBM. Also, highlight that the best split should consider only midpoints between consecutive unique values to reduce redundant evaluations.
Explain the formula for Gini impurity for a single node: 1 - sum(p_i^2), where p_i is the proportion of class i. For binary classification, this simplifies to 2*p*(1-p).
For a split, compute the weighted average of the Gini impurities of the left and right child nodes, weighted by the number of samples in each child. This is the objective to minimize.
For each feature, sort the unique values, consider midpoints as candidate thresholds, and compute the weighted Gini for each. Track the minimum and the corresponding feature and threshold.
Use cumulative sums of class counts to compute Gini for each threshold in O(n) after sorting, avoiding recomputation from scratch. This reduces overall complexity to O(n log n) per feature.
State the time complexity: O(d * n log n) for d features and n samples. Mention that for high-dimensional data, feature subsampling or histogram binning can be used to improve efficiency.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Easier than the first one but I fumbled the 1/n factor at first, wrote the gradient without averaging and had to correct it when they asked me to verify for n=1.
Start by clearly defining the linear regression model and mean squared error loss, then derive the gradients with respect to weights and bias. Implement the update step using the gradients and a learning rate, and finally verify the update with a simple example.
Pro tip: Mention that in practice, you would use vectorized operations for efficiency and that the gradients can be computed in closed form for linear regression, but the same pattern applies to more complex models.
State the linear regression hypothesis: y_pred = Xw + b, and the MSE loss: L = (1/n) * sum((y_pred - y)^2).
Derive the gradients of the loss with respect to weights and bias: dL/dw = (2/n) * X^T (y_pred - y), dL/db = (2/n) * sum(y_pred - y).
Apply the gradient descent update: w_new = w - learning_rate * dL/dw, b_new = b - learning_rate * dL/db.
Write the code for the update step, ensuring correct matrix dimensions, and test with a small dataset to confirm the loss decreases.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.