xlin 0.1.29__py2.py3-none-any.whl → 0.1.31__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
xlin/statistic.py
CHANGED
@@ -203,7 +203,7 @@ def generate_classification_report(predictions: List[str], labels: List[str]) ->
|
|
203
203
|
pred_label = error_label
|
204
204
|
confusion[(true_label, pred_label)] += 1
|
205
205
|
|
206
|
-
confusion_matrix = pd.DataFrame(index=
|
206
|
+
confusion_matrix = pd.DataFrame(index=classes, columns=extend_classes, data=0)
|
207
207
|
for (true, pred), count in confusion.items():
|
208
208
|
confusion_matrix.loc[true, pred] = count
|
209
209
|
|
@@ -212,13 +212,15 @@ def generate_classification_report(predictions: List[str], labels: List[str]) ->
|
|
212
212
|
micro_fp = 0
|
213
213
|
micro_fn = 0
|
214
214
|
class_stats = []
|
215
|
-
for cls in
|
215
|
+
for cls in classes:
|
216
216
|
tp = confusion[(cls, cls)]
|
217
217
|
fp = sum(confusion[(other, cls)] for other in extend_classes if other != cls)
|
218
218
|
fn = sum(confusion[(cls, other)] for other in extend_classes if other != cls)
|
219
|
-
|
220
|
-
|
221
|
-
|
219
|
+
|
220
|
+
if cls != error_label:
|
221
|
+
micro_tp += tp
|
222
|
+
micro_fp += fp
|
223
|
+
micro_fn += fn
|
222
224
|
|
223
225
|
precision = tp / (tp + fp) if (tp + fp) > 0 else 0
|
224
226
|
recall = tp / (tp + fn) if (tp + fn) > 0 else 0
|
@@ -237,8 +239,10 @@ def generate_classification_report(predictions: List[str], labels: List[str]) ->
|
|
237
239
|
# 添加汇总统计
|
238
240
|
class_df = pd.DataFrame(class_stats)
|
239
241
|
report["class_report"] = class_df
|
242
|
+
print(class_df)
|
243
|
+
print(confusion_matrix)
|
240
244
|
confusion_matrix["recall"] = class_df["recall"].values.tolist()
|
241
|
-
p = class_df["precision"].values.tolist() + [
|
245
|
+
p = class_df["precision"].values.tolist() + ["", ""] # [out_of_class, recall]
|
242
246
|
tail = pd.DataFrame([p], index=["precision"], columns=confusion_matrix.columns)
|
243
247
|
confusion_matrix = pd.concat([confusion_matrix, tail], axis=0)
|
244
248
|
confusion_matrix.index.name = "True \\ Pred"
|
@@ -266,6 +270,23 @@ def generate_classification_report(predictions: List[str], labels: List[str]) ->
|
|
266
270
|
return report
|
267
271
|
|
268
272
|
|
273
|
+
def convert_to_jsonable_report(report_row):
|
274
|
+
new_report_json = {}
|
275
|
+
for key, value in report_row.items():
|
276
|
+
if isinstance(value, dict):
|
277
|
+
new_report_json[key] = convert_to_jsonable_report(value)
|
278
|
+
elif isinstance(value, list):
|
279
|
+
new_report_json[key] = [convert_to_jsonable_report(item) if isinstance(item, dict) else item for item in value]
|
280
|
+
elif isinstance(value, pd.DataFrame):
|
281
|
+
if value.index.name is not None:
|
282
|
+
value = value.reset_index()
|
283
|
+
value = value.fillna(-1)
|
284
|
+
new_report_json[key] = value.to_dict(orient="records")
|
285
|
+
else:
|
286
|
+
new_report_json[key] = value
|
287
|
+
return new_report_json
|
288
|
+
|
289
|
+
|
269
290
|
def print_classification_report(predictions: List[str], labels: List[str]):
|
270
291
|
report = generate_classification_report(predictions, labels)
|
271
292
|
"""
|
@@ -4,12 +4,12 @@ xlin/jsonl.py,sha256=IDRydHh2x-8iAGCxt9ScK2wfNLNA40PxNxR5hhr4v6k,7903
|
|
4
4
|
xlin/metric.py,sha256=N7wJ35y-C-IaBr1I1CJ_37lTG7gA69zmn9Xg6xSwKoI,1690
|
5
5
|
xlin/multiprocess_mapping.py,sha256=q4EVU8JPLcRAbNf9NUEzmn8rDLDfIQ3jaW0yxVKPECk,16669
|
6
6
|
xlin/read_as_dataframe.py,sha256=MqY57L7Wp9UoWTRlZLSBKQNaZa-dKw51-ufrKvHKf8s,9041
|
7
|
-
xlin/statistic.py,sha256=
|
7
|
+
xlin/statistic.py,sha256=KOZfvk5qoSs1CNn-NbjEhDlzywtZfAjhu79rRSd0iAg,11332
|
8
8
|
xlin/timing.py,sha256=XMT8dMcMolOMohDvAZOIM_BAiPMREhGQKnO1kc5s6PU,998
|
9
9
|
xlin/util.py,sha256=TTWJaqF5D_r-gAZ_fj0kyHomvCagjwHXQZ2OPSgwd54,10976
|
10
10
|
xlin/xls2xlsx.py,sha256=uSmXcDvIhi5Sq0LGidMXy0wErNBXdjaoa6EftYVjTXs,947
|
11
11
|
xlin/yaml.py,sha256=kICi7G3Td5q2MaSXXt85qNTWoHMgjzt7pvn7r3C4dME,183
|
12
|
-
xlin-0.1.
|
13
|
-
xlin-0.1.
|
14
|
-
xlin-0.1.
|
15
|
-
xlin-0.1.
|
12
|
+
xlin-0.1.31.dist-info/LICENSE,sha256=60ys6rRtc1dZOP8UjSUr9fAqhZudT3WpKe5WbMCralM,1066
|
13
|
+
xlin-0.1.31.dist-info/METADATA,sha256=aTSVecfSW3WNjRBptF43PMCnE0ZprHVsMa-FNdW41Yg,1098
|
14
|
+
xlin-0.1.31.dist-info/WHEEL,sha256=IrRNNNJ-uuL1ggO5qMvT1GGhQVdQU54d6ZpYqEZfEWo,92
|
15
|
+
xlin-0.1.31.dist-info/RECORD,,
|
File without changes
|
File without changes
|