上传文件至 /
This commit is contained in:
58
20260609.5.py
Normal file
58
20260609.5.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
plt.rcParams["font.sans-serif"] = ["SimHei"]
|
||||
plt.rcParams["axes.unicode_minus"] = False
|
||||
|
||||
loss_df = pd.read_csv("loss.csv")
|
||||
plt.figure(figsize=(10, 5))
|
||||
plt.plot(loss_df["epoch"], loss_df["train_loss"], label="训练集loss", color="#2980b9")
|
||||
plt.plot(loss_df["epoch"], loss_df["val_loss"], label="验证集loss", color="#e74c3c")
|
||||
plt.title("MLP模型训练Loss曲线", fontsize=14)
|
||||
plt.xlabel("Epoch")
|
||||
plt.ylabel("Loss值")
|
||||
plt.legend()
|
||||
plt.grid(alpha=0.3)
|
||||
plt.tight_layout()
|
||||
plt.savefig("images/loss_curve.png", dpi=300)
|
||||
plt.show()
|
||||
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
plt.rcParams["font.sans-serif"] = ["SimHei"]
|
||||
plt.rcParams["axes.unicode_minus"] = False
|
||||
|
||||
pred_df = pd.read_csv("predictions.csv")
|
||||
genre_counts = pred_df["pred_label"].value_counts()
|
||||
# 按题目类别顺序排列
|
||||
genre_order = ["剧情", "喜剧", "科幻", "悬疑", "动作", "爱情", "动画", "犯罪", "奇幻", "纪录"]
|
||||
genre_counts = genre_counts.reindex(genre_order, fill_value=0)
|
||||
|
||||
plt.figure(figsize=(12, 6))
|
||||
genre_counts.plot(kind="bar", color="#3498db")
|
||||
plt.title("测试集10个类别的预测分布", fontsize=14)
|
||||
plt.xlabel("电影类别")
|
||||
plt.ylabel("预测数量")
|
||||
plt.xticks(rotation=45)
|
||||
plt.tight_layout()
|
||||
plt.savefig("images/category_bar.png", dpi=300)
|
||||
plt.show()
|
||||
|
||||
from wordcloud import WordCloud
|
||||
import pandas as pd
|
||||
|
||||
df = pd.read_csv("my_labels.csv")
|
||||
all_quotes = " ".join(df["quote"].astype(str))
|
||||
|
||||
wordcloud = WordCloud(
|
||||
font_path="msyh.ttc", # 中文字体路径
|
||||
width=800, height=400, background_color="white"
|
||||
).generate(all_quotes)
|
||||
|
||||
plt.figure(figsize=(10, 5))
|
||||
plt.imshow(wordcloud, interpolation="bilinear")
|
||||
plt.axis("off")
|
||||
plt.tight_layout()
|
||||
plt.savefig("images/wordcloud.png", dpi=300)
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user