将随机森林树写入Excel

时间:2020-05-12 16:26:14

标签: python excel scikit-learn random-forest

model = RandomForestRegressor()    
model.fit(X, y)
r = export_text(model.estimators_[0], feature_names=feature_list)

enter image description here

我正在尝试在Excel工作表中将Random Forest回归树转换为if-then-else语句:

r.to_excel("trees.xlsx")

AttributeError: 'str' object has no attribute 'to_excel'

我还尝试了以下操作,以使r与打印在Excel中的显示完全相同。

workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()
row = 0
col = 0
for x in r():
   worksheet.write(row, col,     str(x[0]))
   worksheet.write(row, col + 1, str(x[1]))
row += 1
workbook.close()

TypeError: 'str' object is not callable

0 个答案:

没有答案