这段代码import numpy import pandas as pd import sklearn data=pd.read_excel("7.xlsx") print(data.head()) x=data.iloc[:,1:14] y=data.iloc[:,0] from sklearn.tree import DecisionTreeClassifier as DTC dtc=DTC(criterion='entropy') dtc.fit(x,y) print("准确率:",dtc.score(x,y)) import matplotlib.pyplot as plt from sklearn import tree a=tree.plot_tree(dtc) plt.savefig("1.png",bbox_inches="tight") plt.savefig("1.png") plt.rcParams["font.sans-serif"]=["KaiTi"] plt.savefig("1.png") a=tree.plot_tree(dtc,feature_names=["对国货的满意度","购买文创类产品意愿","购买国货的频率","产品功能","使用体验","安全保障","外观设计","使用年限","精神需求","价格的重视程度","货宣传印象","购买时更关注","购买原因","倾向内涵"]) import graphviz clf=DTC() clf.fit(x,y) dot_data = tree.export_graphviz(clf,filled=True,rounded=True,special_characters=True , fontname="Microsoft YaHei",feature_names=(["对国货的满意度","购买文创类产品意愿","购买国货的频率","产品功能","使用体验","安全保障","外观设计","使用年限","精神需求","价格的重视程度","货宣传印象","购买时更关注","购买原因","倾向内涵"]) graph = graphviz.Source(dot_data) graph.view()出现invalid syntax错误,怎么改?
时间: 2023-08-24 22:04:35 浏览: 149
numpy_class.7z
这段代码缺少一个右括号 ") ",是这行代码:
dot_data = tree.export_graphviz(clf,filled=True,rounded=True,special_characters=True , fontname="Microsoft YaHei",feature_names=(["对国货的满意度","购买文创类产品意愿","购买国货的频率","产品功能","使用体验","安全保障","外观设计","使用年限","精神需求","价格的重视程度","货宣传印象","购买时更关注","购买原因","倾向内涵"])
将这行代码改为:
dot_data = tree.export_graphviz(clf,filled=True,rounded=True,special_characters=True , fontname="Microsoft YaHei",feature_names=(["对国货的满意度","购买文创类产品意愿","购买国货的频率","产品功能","使用体验","安全保障","外观设计","使用年限","精神需求","价格的重视程度","货宣传印象","购买时更关注","购买原因","倾向内涵"]))
即可。
阅读全文