harbor run -t openthoughts/tasktrove-exp-rpt-issue-issue-2571harbor download openthoughts/tasktrove-exp-rpt-issue-issue-2571Description
Reproduction (for your reference)
Before you implement the fix
# In sklearn/tree/export.py (pre-fix)
def export_text(decision_tree, feature_names=None, max_depth=10,
spacing=3, ...):
...
if feature_names:
feature_names_ = [feature_names[i] for i in tree_.feature]
else:
feature_names_ = ["feature_{}".format(i) for i in tree_.feature]
...
What you will modify
What to implement (high level, no patch details)
Expected behavior after the fix
How to test (suggested quick test)
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree.export import export_text
from sklearn.datasets import load_iris
X, y = load_iris(return_X_y=True)
X = X[:, 0].reshape(-1, 1) # single feature
tree = DecisionTreeClassifier()
tree.fit(X, y)
tree_text = export_text(tree, feature_names=['sepal_length'])
print(tree_text) # should print without raising an exception
Files to create/modify in /app/
Notes
Code blocks for context (for easier editing)
# ... inside export_text(...)
if feature_names:
feature_names_ = [feature_names[i] for i in tree_.feature]
else:
feature_names_ = ["feature_{}".format(i) for i in tree_.feature]
Deliverable
This task is self-contained and does not require cloning the full repository.