生成的決策樹回歸模型中,用graphviz看樹的結構時,有一項mse值,我需要獲取每個葉結點的mse值,根據值大小進行后續的運算,但是看了半天檔案沒找到提供輸出的方法,其他的值像特征名、樣本個數、value等都有提供相應的方法。

用 help(sklearn.tree._tree.Tree)可以看到大部分屬性都提供了方法,唯獨沒看到關于mse的。
uj5u.com熱心網友回復:
用tree_reg.tree_.impurity即可,
tree_reg = tree.DecisionTreeRegressor(max_depth=2)
tree_reg.fit(X_train, y_train)
extracted_MSEs = tree_reg.tree_.impurity # 獲取MSE值
for idx, MSE in enumerate(tree_reg.tree_.impurity):
print("Node {} has MSE {}".format(idx,MSE))
Node 0 has MSE 86.873403833
Node 1 has MSE 40.3211827171
Node 2 has MSE 25.6934820064
Node 3 has MSE 19.0053469592
Node 4 has MSE 74.6839429717
Node 5 has MSE 38.3057346817
Node 6 has MSE 39.6709615385
自答一波,還是學的不扎實,關于決策樹中的impurity理解不到位。
uj5u.com熱心網友回復:
想問下,這圖中的mse和value值是怎么計算的呀轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/76649.html
下一篇:pycharm的安裝
