xlin 0.1.28__tar.gz → 0.1.30__tar.gz
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-0.1.28 → xlin-0.1.30}/PKG-INFO +1 -1
- {xlin-0.1.28 → xlin-0.1.30}/pyproject.toml +1 -1
- {xlin-0.1.28 → xlin-0.1.30}/xlin/statistic.py +60 -3
- {xlin-0.1.28 → xlin-0.1.30}/LICENSE +0 -0
- {xlin-0.1.28 → xlin-0.1.30}/README.md +0 -0
- {xlin-0.1.28 → xlin-0.1.30}/xlin/__init__.py +0 -0
- {xlin-0.1.28 → xlin-0.1.30}/xlin/ischinese.py +0 -0
- {xlin-0.1.28 → xlin-0.1.30}/xlin/jsonl.py +0 -0
- {xlin-0.1.28 → xlin-0.1.30}/xlin/metric.py +0 -0
- {xlin-0.1.28 → xlin-0.1.30}/xlin/multiprocess_mapping.py +0 -0
- {xlin-0.1.28 → xlin-0.1.30}/xlin/read_as_dataframe.py +0 -0
- {xlin-0.1.28 → xlin-0.1.30}/xlin/timing.py +0 -0
- {xlin-0.1.28 → xlin-0.1.30}/xlin/util.py +0 -0
- {xlin-0.1.28 → xlin-0.1.30}/xlin/xls2xlsx.py +0 -0
- {xlin-0.1.28 → xlin-0.1.30}/xlin/yaml.py +0 -0
@@ -111,11 +111,53 @@ Kurtosis: {float((data - mean).mean()**4 / std**4):.4f}\
|
|
111
111
|
plt.show()
|
112
112
|
|
113
113
|
|
114
|
-
|
114
|
+
|
115
|
+
def draw_preds_labels(preds: list[str], labels: list[str]):
|
116
|
+
from collections import Counter
|
115
117
|
import matplotlib.pyplot as plt
|
116
118
|
|
117
|
-
|
118
|
-
|
119
|
+
out_of_class = "out_of_class"
|
120
|
+
valid_values = list(set(labels)) + [out_of_class]
|
121
|
+
valid_preds = []
|
122
|
+
for pred in preds:
|
123
|
+
if pred not in valid_values:
|
124
|
+
valid_preds.append(out_of_class)
|
125
|
+
else:
|
126
|
+
valid_preds.append(pred)
|
127
|
+
|
128
|
+
counter = Counter(valid_preds)
|
129
|
+
pred_labels = list(counter.keys())
|
130
|
+
pred_values = list(counter.values())
|
131
|
+
|
132
|
+
# 绘制柱状图 pred
|
133
|
+
plt.figure(figsize=(12, 12))
|
134
|
+
plt.subplot(2, 2, 1)
|
135
|
+
plt.bar(pred_labels, pred_values)
|
136
|
+
plt.xlabel("class")
|
137
|
+
plt.ylabel("count")
|
138
|
+
plt.title("pred class distribution")
|
139
|
+
|
140
|
+
# 绘制饼图 pred
|
141
|
+
plt.subplot(2, 2, 2)
|
142
|
+
plt.pie(pred_values, labels=pred_labels, autopct="%1.1f%%")
|
143
|
+
plt.title("pred class distribution")
|
144
|
+
|
145
|
+
# 绘制柱状图 label
|
146
|
+
counter = Counter(labels)
|
147
|
+
label_labels = list(counter.keys())
|
148
|
+
label_values = list(counter.values())
|
149
|
+
plt.subplot(2, 2, 3)
|
150
|
+
plt.bar(label_labels, label_values)
|
151
|
+
plt.xlabel("class")
|
152
|
+
plt.ylabel("count")
|
153
|
+
plt.title("label class distribution")
|
154
|
+
# 绘制饼图 label
|
155
|
+
plt.subplot(2, 2, 4)
|
156
|
+
plt.pie(label_values, labels=label_labels, autopct="%1.1f%%")
|
157
|
+
plt.title("label class distribution")
|
158
|
+
plt.suptitle("Pred and Label Class Distribution")
|
159
|
+
|
160
|
+
plt.tight_layout()
|
119
161
|
plt.show()
|
120
162
|
|
121
163
|
|
@@ -224,6 +266,20 @@ def generate_classification_report(predictions: List[str], labels: List[str]) ->
|
|
224
266
|
return report
|
225
267
|
|
226
268
|
|
269
|
+
def convert_to_jsonable_report(report_row):
|
270
|
+
new_report_json = {}
|
271
|
+
for key, value in report_row.items():
|
272
|
+
if isinstance(value, dict):
|
273
|
+
new_report_json[key] = convert_to_jsonable_report(value)
|
274
|
+
elif isinstance(value, list):
|
275
|
+
new_report_json[key] = [convert_to_jsonable_report(item) if isinstance(item, dict) else item for item in value]
|
276
|
+
elif isinstance(value, pd.DataFrame):
|
277
|
+
new_report_json[key] = value.fillna(-1).to_dict(orient="records")
|
278
|
+
else:
|
279
|
+
new_report_json[key] = value
|
280
|
+
return new_report_json
|
281
|
+
|
282
|
+
|
227
283
|
def print_classification_report(predictions: List[str], labels: List[str]):
|
228
284
|
report = generate_classification_report(predictions, labels)
|
229
285
|
"""
|
@@ -256,6 +312,7 @@ def print_classification_report(predictions: List[str], labels: List[str]):
|
|
256
312
|
print("=== 分类报告 ===")
|
257
313
|
print(report["class_report"])
|
258
314
|
print()
|
315
|
+
return report
|
259
316
|
|
260
317
|
|
261
318
|
if __name__ == "__main__":
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|