Я запускаю эту ячейку в Jupyter Notebook:
Код: Выделить всё
fig = plt.figure(figsize=(25,20))
tree.plot_tree(clf)
plt.show()
Код: Выделить всё
---------------------------------------------------------------------------
NotFittedError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_8784\285030017.py in
1 fig = plt.figure(figsize=(25,20))
----> 2 tree.plot_tree(clf)
3 plt.show()
~\.conda\envs\electricvehiclepriceprediction\lib\site-packages\sklearn\tree\_export.py in plot_tree(decision_tree, max_depth, feature_names, class_names, label, filled, impurity, node_ids, proportion, rounded, precision, ax, fontsize)
178 """
179
--> 180 check_is_fitted(decision_tree)
181
182 exporter = _MPLTreeExporter(
~\.conda\envs\electricvehiclepriceprediction\lib\site-packages\sklearn\utils\validation.py in check_is_fitted(estimator, attributes, msg, all_or_any)
1220
1221 if not fitted:
-> 1222 raise NotFittedError(msg % {"name": type(estimator).__name__})
1223
1224
NotFittedError: This DecisionTreeClassifier instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.
Я пробовал использовать следующий код:
Код: Выделить всё
tree_clf = DecisionTreeClassifier(max_depth=2, random_state=42)
tree_clf.fit(X_test, y_test)
DecisionTreeClassifier(max_depth=2, random_state=42)
clf = tree.DecisionTreeClassifier(random_state=0)
fig = plt.figure(figsize=(25,20))
tree.plot_tree(clf)
plt.show()
Как решить эту проблему?
Подробнее здесь: https://stackoverflow.com/questions/792 ... -in-jupyte