← 返回 anthropic 的题目列表Debug / Fix an Extremely Randomized Trees (ExtraTrees) Implementation in NumPy
类型:online_judge
Task: Debug / Fix an Extremely Randomized Trees (ExtraTrees) Implementation in NumPy
You are given a NumPy-only implementation of Extremely Randomized Trees (ExtraTrees) for either classification or regression. The code contains bugs that cause one or more of the following:
training crashes (shape/indexing/numerical issues), or
training runs but predictions do not match expected outputs, or
results are not reproducible / randomness does not match the intended behavior.
Without introducing any third-party libraries beyond NumPy, identify and fix the issues so that the implementation passes the provided unit tests / validation script.
Required functionality (follow the provided code/tests)
fit(X, y): train an ensemble of extremely randomized trees.
predict(X): generate predictions; for classification, return class labels (or the probability/score format required by the tests); for regression, return continuous values.
Randomness: when a seed is provided (e.g., random_state), results must be reproducible.
Constraints
Use Python + NumPy only.
You may refactor internal logic as needed, but must keep the public API compatible with the tests.
All provided tests must pass.
I/O (test-driven)
Training input:
X: np.ndarray of shape (n_samples, n_features)
y: np.ndarray of shape (n_samples,) or (n_samples, 1)
Prediction output:
Regression: shape (n_samples,)
Classification: shape (n_samples,) (class ids) or an equivalent format required by the tests
Example (format only; follow the real tests)
Input: X is 100x10, y has length 100
Output: predict(X_test) returns an array of length len(X_test)
Note: This is a take-home/debug style task. The core is reading existing code, locating bugs, and fixing behavior to match the ExtraTrees definition and the provided tests.
Example
Input
(Provided by take-home: code + failing unit tests)
Output
All unit tests pass; deterministic outputs under fixed seed