数据源:http://grouplens.org/dataset/movieslens,观影人员评价总体可视化的代码
时间: 2023-06-30 17:23:48 浏览: 135
is waiting...\n");
return;
}
buffer--;
printf("Consumer consumes a data item. Buffer size = %d\n", buffer);
if (buffer == 0) {
buffer_empty = 1;
}
if (buffer == buffer_size -你可以使用Python中的pandas和matplotlib库对该数据集进行处理和可视化。以下是一个简单的代码 1) {
buffer_full = 0;
}
}
int main() {
int i, time = 0, completed =示例:
```python
import pandas as pd
import matplotlib.pyplot as plt
# 读取数据集
movies = pd.read_csv 0;
float avg_turnaround_time = 0.0, avg_waiting_time = 0.0;
PCB processes[MAX_PROCESS];
// 初始化生产者和消费者进程
processes[0].pid = 1;
processes[0].('movies.csv')
ratings = pd.read_csv('ratings.csv')
# 合并数据集
movie_ratings = pd.merge(movies, ratings,arrival_time = 0;
processes[0].burst_time = 0;
processes[0].remaining_time = 0;
processes[0].type = 0;
processes[0].buffer = 0;
processes[1].pid = 2;
on='movieId')
# 按照电影评分计算平均评分和评分次数
mean_ratings = movie_ratings processes[1].arrival_time = 0;
processes[1].burst_time = 0;
processes[1].remaining_time.groupby('title')['rating'].mean()
count_ratings = movie_ratings.groupby('title')['rating'].count()
# 绘制直方图
plt = 0;
processes[1].type = 1;
processes[1].buffer = 0;
// 将生产.hist(mean_ratings, bins=50)
plt.xlabel('Average Rating')
plt.ylabel('Number of Movies')
plt.title('Distribution of Movie Ratings')
者和消费者进程加入到就绪队列中
enqueue(processes[0]);
enqueue(processes[1]);
while (completed < MAX_PROCESS) {
PCB process = dequeue();
if (process.type == 0) {
//plt.show()
# 绘制散点图
plt.scatter(mean_ratings, count_ratings)
plt.xlabel('Average Rating')
plt.ylabel('Number of 生产者进程
printf("Time %d: Producer process %d is running...\n", time, process.pid);
Ratings')
plt.title('Movie Ratings vs. Number of Ratings')
plt.show()
```
这段代码将读取movies.csv和ratings.csv produce();
} else {
// 消费者进程
printf("Time %d: Consumer process %d is running...\n", time, process.pid);
consume();
}
time++;
process.remaining_time--;
if (process.remaining_time > 两个文件,将它们合并成一个数据集,并计算每部电影的平均评分和评分次0) {
enqueue(process);
} else {
completed++;
process.completion_time = time;
process.turnaround_time =数。然后,它将使用matplotlib库绘制两个图表:一个是电影评分的分布直方图 process.completion_time - process.arrival_time;
process.waiting_time = process.turnaround_time - process.burst_time;
avg,另一个是电影评分与评分次数的散点图。这两个图表可以帮助你进行总_turnaround_time += process.turnaround_time;
avg_waiting_time += process.waiting_time;
}
if (front != rear)体可视化分析。
阅读全文