完成期末练习
This commit is contained in:
102
q2_1_crawler/movie.html
Normal file
102
q2_1_crawler/movie.html
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "1",
|
||||||
|
"title": "阿甘正传",
|
||||||
|
"director": "Frank Darabont",
|
||||||
|
"year": "2023",
|
||||||
|
"rating": "8.5",
|
||||||
|
"duration": "112",
|
||||||
|
"genre": "科幻",
|
||||||
|
"actors_count": "4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2",
|
||||||
|
"title": "忠犬八公的故事",
|
||||||
|
"director": "陈凯歌",
|
||||||
|
"year": "2023",
|
||||||
|
"rating": "6.9",
|
||||||
|
"duration": "102",
|
||||||
|
"genre": "动画",
|
||||||
|
"actors_count": "4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "3",
|
||||||
|
"title": "放牛班的春天",
|
||||||
|
"director": "Robert Zemeckis",
|
||||||
|
"year": "1993",
|
||||||
|
"rating": "7.6",
|
||||||
|
"duration": "175",
|
||||||
|
"genre": "动画",
|
||||||
|
"actors_count": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "4",
|
||||||
|
"title": "星际穿越",
|
||||||
|
"director": "James Cameron",
|
||||||
|
"year": "2024",
|
||||||
|
"rating": "9.1",
|
||||||
|
"duration": "92",
|
||||||
|
"genre": "喜剧",
|
||||||
|
"actors_count": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "5",
|
||||||
|
"title": "千与千寻",
|
||||||
|
"director": "宫崎骏",
|
||||||
|
"year": "2007",
|
||||||
|
"rating": "8.3",
|
||||||
|
"duration": "146",
|
||||||
|
"genre": "悬疑",
|
||||||
|
"actors_count": "4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "6",
|
||||||
|
"title": "肖申克的救赎",
|
||||||
|
"director": "Christopher Nolan",
|
||||||
|
"year": "1997",
|
||||||
|
"rating": "8.3",
|
||||||
|
"duration": "117",
|
||||||
|
"genre": "爱情",
|
||||||
|
"actors_count": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "7",
|
||||||
|
"title": "盗梦空间",
|
||||||
|
"director": "Lasse Hallström",
|
||||||
|
"year": "2001",
|
||||||
|
"rating": "7.5",
|
||||||
|
"duration": "131",
|
||||||
|
"genre": "悬疑",
|
||||||
|
"actors_count": "3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "8",
|
||||||
|
"title": "泰坦尼克号",
|
||||||
|
"director": "Rajkumar Hirani",
|
||||||
|
"year": "1994",
|
||||||
|
"rating": "6.8",
|
||||||
|
"duration": "163",
|
||||||
|
"genre": "喜剧",
|
||||||
|
"actors_count": "4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "9",
|
||||||
|
"title": "三傻大闹宝莱坞",
|
||||||
|
"director": "Christophe Barratier",
|
||||||
|
"year": "1997",
|
||||||
|
"rating": "6.8",
|
||||||
|
"duration": "107",
|
||||||
|
"genre": "冒险",
|
||||||
|
"actors_count": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "10",
|
||||||
|
"title": "霸王别姬",
|
||||||
|
"director": "Christopher Nolan",
|
||||||
|
"year": "2006",
|
||||||
|
"rating": "9.1",
|
||||||
|
"duration": "98",
|
||||||
|
"genre": "科幻",
|
||||||
|
"actors_count": "2"
|
||||||
|
}
|
||||||
|
]
|
||||||
102
q2_1_crawler/movie.json
Normal file
102
q2_1_crawler/movie.json
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "1",
|
||||||
|
"title": "阿甘正传",
|
||||||
|
"director": "Frank Darabont",
|
||||||
|
"year": "2023",
|
||||||
|
"rating": "8.5",
|
||||||
|
"duration": "112",
|
||||||
|
"genre": "科幻",
|
||||||
|
"actors_count": "4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2",
|
||||||
|
"title": "忠犬八公的故事",
|
||||||
|
"director": "陈凯歌",
|
||||||
|
"year": "2023",
|
||||||
|
"rating": "6.9",
|
||||||
|
"duration": "102",
|
||||||
|
"genre": "动画",
|
||||||
|
"actors_count": "4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "3",
|
||||||
|
"title": "放牛班的春天",
|
||||||
|
"director": "Robert Zemeckis",
|
||||||
|
"year": "1993",
|
||||||
|
"rating": "7.6",
|
||||||
|
"duration": "175",
|
||||||
|
"genre": "动画",
|
||||||
|
"actors_count": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "4",
|
||||||
|
"title": "星际穿越",
|
||||||
|
"director": "James Cameron",
|
||||||
|
"year": "2024",
|
||||||
|
"rating": "9.1",
|
||||||
|
"duration": "92",
|
||||||
|
"genre": "喜剧",
|
||||||
|
"actors_count": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "5",
|
||||||
|
"title": "千与千寻",
|
||||||
|
"director": "宫崎骏",
|
||||||
|
"year": "2007",
|
||||||
|
"rating": "8.3",
|
||||||
|
"duration": "146",
|
||||||
|
"genre": "悬疑",
|
||||||
|
"actors_count": "4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "6",
|
||||||
|
"title": "肖申克的救赎",
|
||||||
|
"director": "Christopher Nolan",
|
||||||
|
"year": "1997",
|
||||||
|
"rating": "8.3",
|
||||||
|
"duration": "117",
|
||||||
|
"genre": "爱情",
|
||||||
|
"actors_count": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "7",
|
||||||
|
"title": "盗梦空间",
|
||||||
|
"director": "Lasse Hallström",
|
||||||
|
"year": "2001",
|
||||||
|
"rating": "7.5",
|
||||||
|
"duration": "131",
|
||||||
|
"genre": "悬疑",
|
||||||
|
"actors_count": "3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "8",
|
||||||
|
"title": "泰坦尼克号",
|
||||||
|
"director": "Rajkumar Hirani",
|
||||||
|
"year": "1994",
|
||||||
|
"rating": "6.8",
|
||||||
|
"duration": "163",
|
||||||
|
"genre": "喜剧",
|
||||||
|
"actors_count": "4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "9",
|
||||||
|
"title": "三傻大闹宝莱坞",
|
||||||
|
"director": "Christophe Barratier",
|
||||||
|
"year": "1997",
|
||||||
|
"rating": "6.8",
|
||||||
|
"duration": "107",
|
||||||
|
"genre": "冒险",
|
||||||
|
"actors_count": "5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "10",
|
||||||
|
"title": "霸王别姬",
|
||||||
|
"director": "Christopher Nolan",
|
||||||
|
"year": "2006",
|
||||||
|
"rating": "9.1",
|
||||||
|
"duration": "98",
|
||||||
|
"genre": "科幻",
|
||||||
|
"actors_count": "2"
|
||||||
|
}
|
||||||
|
]
|
||||||
48
q2_1_crawler/q2_1.py
Normal file
48
q2_1_crawler/q2_1.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup as bs
|
||||||
|
import json
|
||||||
|
|
||||||
|
url = 'https://exam.detr.top/exam-b/movies'
|
||||||
|
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36 Edg/149.0.0.0',
|
||||||
|
'Referer':'https://exam.detr.top/exam-b/movies'}
|
||||||
|
req = requests.get(url, headers=headers)
|
||||||
|
req.encoding="utf-8"
|
||||||
|
|
||||||
|
data=[]
|
||||||
|
|
||||||
|
soup=bs(req.text,"html.parser")
|
||||||
|
# print(soup)
|
||||||
|
#id, title, director, year, rating, duration, genre, actors-count
|
||||||
|
|
||||||
|
items=soup.select('.item-row')
|
||||||
|
# movie_list=[]
|
||||||
|
for i in range(len(items)):
|
||||||
|
id=items[i].find("td",class_="item-id").get_text()
|
||||||
|
title=items[i].find("td",class_="item-title").get_text().strip()
|
||||||
|
director=items[i].find("td",class_="item-director").get_text().strip()
|
||||||
|
year=items[i].find("td",class_="item-year").get_text()
|
||||||
|
rating=items[i].find("td",class_="item-rating").get_text()
|
||||||
|
duration=items[i].find("td",class_="item-duration").get_text()
|
||||||
|
genre=items[i].find("td",class_="item-genre").get_text()
|
||||||
|
actors_count=items[i].find("td",class_="item-actors-count").get_text()
|
||||||
|
|
||||||
|
data.append({
|
||||||
|
"id":id,
|
||||||
|
"title":title,
|
||||||
|
"director":director,
|
||||||
|
"year":year,
|
||||||
|
"rating":rating,
|
||||||
|
"duration":duration,
|
||||||
|
"genre":genre,
|
||||||
|
"actors_count":actors_count
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
print(data)
|
||||||
|
|
||||||
|
|
||||||
|
with open('movie.json', 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
|
with open("movie.html","w",encoding='utf-8') as f:
|
||||||
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||||
43
q2_1_crawler/q2_2.py
Normal file
43
q2_1_crawler/q2_2.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# ① 找出评分最高和最低的电影,打印电影名 + 评分。
|
||||||
|
# ② 统计各类型的电影数量,用字典格式输出。
|
||||||
|
# ③ 统计各导演的电影数量,用字典格式输出。
|
||||||
|
# ④ 统计 2020 年(含)以后上映的电影数量。
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
with open('movie.json', 'r', encoding='utf-8') as f:
|
||||||
|
data=json.load(f)
|
||||||
|
# print(data)
|
||||||
|
|
||||||
|
|
||||||
|
sort_movie=sorted(data,key=lambda x:x["rating"])
|
||||||
|
min=sort_movie[0]
|
||||||
|
max=sort_movie[-1]
|
||||||
|
print("评分最低的电影",min["title"],min["rating"])
|
||||||
|
print("评分最高的电影",max["title"],max["rating"])
|
||||||
|
|
||||||
|
genre_shu={}
|
||||||
|
for g in data:
|
||||||
|
ge=g["genre"]
|
||||||
|
if ge in genre_shu:
|
||||||
|
genre_shu[ge]+=1
|
||||||
|
else:
|
||||||
|
genre_shu[ge]=1
|
||||||
|
print("各类型的电影数量",genre_shu)
|
||||||
|
|
||||||
|
director_shu={}
|
||||||
|
for d in data:
|
||||||
|
di=d["director"]
|
||||||
|
if di in director_shu:
|
||||||
|
director_shu[di]+=1
|
||||||
|
else:
|
||||||
|
director_shu[di]=1
|
||||||
|
print("各导演的电影数量",director_shu)
|
||||||
|
|
||||||
|
a=0
|
||||||
|
for y in data:
|
||||||
|
if int(y["year"]) >= 2020:
|
||||||
|
a+=1
|
||||||
|
print("2020 年(含)以后上映的电影数量",a)
|
||||||
BIN
q3/q3_1/q3_1_image_label.zip
Normal file
BIN
q3/q3_1/q3_1_image_label.zip
Normal file
Binary file not shown.
1
q3/q3_2/q3_2_takeout_reviews.json
Normal file
1
q3/q3_2/q3_2_takeout_reviews.json
Normal file
File diff suppressed because one or more lines are too long
9
q3/q3_3_质量自评.md
Normal file
9
q3/q3_3_质量自评.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
标注质量自评
|
||||||
|
1.标注前准备
|
||||||
|
本次文本情感分类标注规范:仅设置(正面)(负面)俩类标签,一条评论只能标注单一情感,无中立标签;判断依据以用户核心情绪、评价倾向为准,忽略无关客观描述。标注前查看2条示例评论,明确极端好评、差评的区别边界,统一判定标准。
|
||||||
|
|
||||||
|
2.标注过程
|
||||||
|
困难:部分评论同时存在优缺点混合描述,情感倾向模糊。解决方法:抓取句子核心总结、整体推荐态度,以最终情绪导向判定;不确定样本反复重读全文,不随意打标签,保证标签唯一。
|
||||||
|
|
||||||
|
3.标注后检查
|
||||||
|
逐条核对5条评论,确保每条都存在id、text、sentiment字段,无漏标数据;没有导入重复数据,全部素材仅标注一次,导出JSON校验字段格式符合作业要求,无缺失、错标。
|
||||||
40
q4/q4_1/q4_1.py
Normal file
40
q4/q4_1/q4_1.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
with open(r'D:\桌面\期末考试\simulated-examination\q2_1_crawler\movie.json', 'r', encoding='utf-8') as f:
|
||||||
|
data=json.load(f)
|
||||||
|
# print(data)
|
||||||
|
|
||||||
|
genre_shu={}
|
||||||
|
for g in data:
|
||||||
|
ge=g["genre"]
|
||||||
|
if ge in genre_shu:
|
||||||
|
genre_shu[ge]+=1
|
||||||
|
else:
|
||||||
|
genre_shu[ge]=1
|
||||||
|
# print("各类型的电影数量",genre_shu)
|
||||||
|
|
||||||
|
genre_lei=list(genre_shu.keys())
|
||||||
|
genre_liang=list(genre_shu.values())
|
||||||
|
|
||||||
|
print(genre_liang)
|
||||||
|
|
||||||
|
plt.figure(figsize=(14, 12))
|
||||||
|
plt.bar(genre_lei, genre_liang,
|
||||||
|
width=0.6)
|
||||||
|
|
||||||
|
# 标题和标签
|
||||||
|
plt.title('类型电影数量分布', fontsize=14)
|
||||||
|
plt.xlabel('类型名称', fontsize=12)
|
||||||
|
plt.ylabel('电影数量', fontsize=12)
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
save_path = os.path.join(os.path.dirname(__file__),"q4_1_bar.png")
|
||||||
|
plt.savefig(save_path, dpi=150,format='png')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#with open('movie.json', 'r', encoding='utf-8') as f:
|
||||||
BIN
q4/q4_1/q4_1_bar.png
Normal file
BIN
q4/q4_1/q4_1_bar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
28
q4/q4_2/q4_2.py
Normal file
28
q4/q4_2/q4_2.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import json
|
||||||
|
|
||||||
|
rating=[]
|
||||||
|
duration=[]
|
||||||
|
|
||||||
|
with open(r'D:\桌面\期末考试\simulated-examination\q2_1_crawler\movie.json', 'r', encoding='utf-8') as f:
|
||||||
|
data=json.load(f)
|
||||||
|
# print(data)
|
||||||
|
for i in data:
|
||||||
|
rating.append(i["rating"])
|
||||||
|
duration.append(i["duration"])
|
||||||
|
plt.figure(figsize=(12, 8))
|
||||||
|
plt.scatter(duration, rating,
|
||||||
|
c='red',
|
||||||
|
s=80, # 点的大小
|
||||||
|
alpha=0.6, # 透明度
|
||||||
|
edgecolors='white') # 点的边框
|
||||||
|
plt.title('时长与评分关系散点图', fontsize=14)
|
||||||
|
plt.xlabel('时长', fontsize=12)
|
||||||
|
plt.ylabel('评分', fontsize=12)
|
||||||
|
plt.grid(True, linestyle='--', alpha=0.5)
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
save_path = os.path.join(os.path.dirname(__file__),"q4_2_scatter.png")
|
||||||
|
plt.savefig(save_path, dpi=150,format='png')
|
||||||
|
plt.show()
|
||||||
BIN
q4/q4_2/q4_2_scatter.png
Normal file
BIN
q4/q4_2/q4_2_scatter.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
24
q4/q4_3a/q4_3a.py
Normal file
24
q4/q4_3a/q4_3a.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import json
|
||||||
|
|
||||||
|
rating=[]
|
||||||
|
|
||||||
|
with open(r'D:\桌面\期末考试\simulated-examination\q2_1_crawler\movie.json', 'r', encoding='utf-8') as f:
|
||||||
|
data=json.load(f)
|
||||||
|
# print(data)
|
||||||
|
for i in data:
|
||||||
|
rating.append(i["rating"])
|
||||||
|
|
||||||
|
plt.figure(figsize=(12,8))
|
||||||
|
plt.hist(rating, # 数据
|
||||||
|
bins=10, # 分成几个柱子
|
||||||
|
color='#3498DB', # 颜色
|
||||||
|
edgecolor='white') # 柱子边框颜色
|
||||||
|
plt.title('评分分布', fontsize=14)
|
||||||
|
plt.xlabel('评分', fontsize=13)
|
||||||
|
plt.grid(True, linestyle='--', alpha=0.5, axis='y')
|
||||||
|
|
||||||
|
import os
|
||||||
|
save_path = os.path.join(os.path.dirname(__file__),"q4_3a_hist.png")
|
||||||
|
plt.savefig(save_path, dpi=150,format='png')
|
||||||
|
plt.show()
|
||||||
BIN
q4/q4_3a/q4_3a_hist.png
Normal file
BIN
q4/q4_3a/q4_3a_hist.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
24
q4/q4_3b/q4_3b.py
Normal file
24
q4/q4_3b/q4_3b.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import json
|
||||||
|
duration=[]
|
||||||
|
|
||||||
|
with open(r'D:\桌面\期末考试\simulated-examination\q2_1_crawler\movie.json', 'r', encoding='utf-8') as f:
|
||||||
|
data=json.load(f)
|
||||||
|
# print(data)
|
||||||
|
for i in data:
|
||||||
|
duration.append(i["duration"])
|
||||||
|
|
||||||
|
plt.figure(figsize=(12,8))
|
||||||
|
plt.hist( duration, # 数据
|
||||||
|
bins=10, # 分成几个柱子
|
||||||
|
color='#3498DB', # 颜色
|
||||||
|
edgecolor='white') # 柱子边框颜色
|
||||||
|
plt.title('时长分布', fontsize=14)
|
||||||
|
plt.xlabel('时长(分钟)', fontsize=13)
|
||||||
|
plt.grid(True, linestyle='--', alpha=0.5, axis='y')
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
save_path = os.path.join(os.path.dirname(__file__),"q4_3b_hist.png")
|
||||||
|
plt.savefig(save_path, dpi=150,format='png')
|
||||||
|
plt.show()
|
||||||
BIN
q4/q4_3b/q4_3b_hist.png
Normal file
BIN
q4/q4_3b/q4_3b_hist.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
Reference in New Issue
Block a user