我有一本字典:
{'DATE': 65,
'ORG': 93,
'PERSON': 62,
'GPE': 18,
'PRODUCT': 18,
'FAC': 4,
'CARDINAL': 50,
'ORDINAL': 15,
'NORP': 10,
'MONEY': 3,
'PERCENT': 2,
'TIME': 5,
'LOC': 5,
'QUANTITY': 2}
Run Code Online (Sandbox Code Playgroud)
我想要的只是将其绘制在饼图中,显示这些项目的百分比分布。我该如何绘制这个???
我在这里尝试了解决方案:尝试根据下面的数据创建饼图和条形图
所以我使用在那里发布的代码作为解决方案:
amount_of_TP_ner_tags # this is the dictionary I want to plot. see above
# dont use values inside a list as column values for a dataframe
browser2 = {}
[browser2.update({key : val[0]}) for key, val in amount_of_TP_ner_tags.items()]
x = pd.Series(browser2)
y = pd.Series.sort_values(x)
z = pd.DataFrame(y) …Run Code Online (Sandbox Code Playgroud) 我想计算我的模型的 F1 分数。但我收到警告并得到 0.0 F1 分数,但我不知道该怎么办。
这是源代码:
def model_evaluation(dict):
for key,value in dict.items():
classifier = Pipeline([('tfidf', TfidfVectorizer()),
('clf', value),
])
classifier.fit(X_train, y_train)
predictions = classifier.predict(X_test)
print("Accuracy Score of" , key , ": ", metrics.accuracy_score(y_test,predictions))
print(metrics.classification_report(y_test,predictions))
print(metrics.f1_score(y_test, predictions, average="weighted", labels=np.unique(predictions), zero_division=0))
print("---------------","\n")
dlist = { "KNeighborsClassifier": KNeighborsClassifier(3),"LinearSVC":
LinearSVC(), "MultinomialNB": MultinomialNB(), "RandomForest": RandomForestClassifier(max_depth=5, n_estimators=100)}
model_evaluation(dlist)
Run Code Online (Sandbox Code Playgroud)
这是结果:
Accuracy Score of KNeighborsClassifier : 0.75
precision recall f1-score support
not positive 0.71 0.77 0.74 13
positive 0.79 0.73 0.76 15
accuracy 0.75 28
macro avg …Run Code Online (Sandbox Code Playgroud)