首先,本文的数据下载自IMDB 5000 Movie Dataset From Kaggle**
原作者爬取了IMDB 5000多条观测数据,然后用回归对IMDB各个电影的评分进行建模,作者的文章如下:
Predict Movie Rating - NYC Data Science Academy Blog**
本文主要借助该数据完成大数据分析第4讲复杂数据和分析的作业,对该讲的内容和知识点练练手。
导入相关包
library(ggplot2)
library(stringr)
library(dplyr)
数据导入
#当前项目运行根路径
#例如:G:/DataCruiser/workspace/IMDB Analysis
projectPath <- getwd()
#movie_metadata.csv路径
#例如G:/DataCruiser/workspace/IMDB Analysis/data/movie_metadata.csv
servicePath <- str_c(projectPath, "data", "movie_metadata.csv", sep = "/")
#导入数据
movies <- read.csv(servicePath, header = T, stringsAsFactors = F)
导演与电影评分数据处理
disDirector <- function(){
#选择子集
mymovies <- select(movies,
title_year,
imdb_score,
director_facebook_likes,
actor_1_facebook_likes)
#列名重命名,等号左边是新列名,右边是就列名
mymovies <- rename(mymovies,
year = title_year,
scores = imdb_score,
direcotrlikes = director_facebook_likes,
actorlikes = actor_1_facebook_likes)
#删除缺失数据
mymovies <- filter(mymovies,
!is.na(year),
!is.na(scores),
!is.na(direcotrlikes),
!is.na(actorlikes))
#数据排序
mymovies <- arrange(mymovies, desc(year))
#数据计算:facebook上导演点赞数与相应导演所导的电影IMDB评分数之间的关系
disDirector <- mymovies %>%
group_by(year) %>%
summarise( count = n(),
mean_scores = mean(scores, na.rm = TRUE),
mean_likes = mean(direcotrlikes, na.rm = TRUE) )
%>% filter(count > 0)
return(disDirector)
}
演员与电影评分数据处理
disActor <- function(){
#选择子集
mymovies <- select(movies,
title_year,
imdb_score,
director_facebook_likes,
actor_1_facebook_likes)
#列名重命名,等号左边是新列名,右边是就列名
mymovies <- rename(mymovies,
year = title_year,
scores = imdb_score,
direcotrlikes = director_facebook_likes,
actorlikes = actor_1_facebook_likes)
#删除缺失数据 mymovies <- filter(mymovies,
!is.na(year),
!is.na(scores),
!is.na(direcotrlikes),
!is.na(actorlikes))
#数据排序 mymovies <- arrange(mymovies, desc(year))
#数据计算:facebook上一号演员点赞数与相应导演所导的电影IMDB评分数之间的关系
disActor <- mymovies %>%
group_by(year) %>%
summarise( count = n(),
mean_scores = mean(scores, na.rm = TRUE),
mean_likes = mean(actorlikes, na.rm = TRUE) )
%>% filter(count > 0)
return(disActor)
}
导演与评分图形绘制
#导演评分散点图
directorView <- ggplot(data = disDirector) +
geom_point(mapping = aes(x = mean_likes, y = mean_scores))+
geom_smooth(mapping = aes(x = mean_likes, y = mean_scores))
结果如下:
演员与评分图形绘制
#演员评分散点图
actorView <- ggplot(data = disActor) +
geom_point(mapping = aes(x = mean_likes, y = mean_scores))+
geom_smooth(mapping = aes(x = mean_likes, y = mean_scores))
结果如下:
结果保存
#保存分析结果
outputpath <- str_c(projectPath,"output","movieScore vs direcetorLikes.jpg",sep="/")
ggsave(filename=outputpath, plot=directorView)
#保存分析结果
outputpath <- str_c(projectPath,"output","movieScore vs actorLikes.jpg",sep="/")
ggsave(filename=outputpath, plot=actorView)
结果分析
在假定IMDB评分高低决定着电影好坏的前提下,从对IMDB 5000多条的数据分析可以初步得到以下结论:
- 总体上看导演在facebook上面获得的点赞数与电影的好坏呈现正相关,而一号演员在facebook获得的点赞数与电影的好坏呈负相关,通过导演的好坏来判断一部电影的好坏往往更加靠谱;
- 有一些非主流的导演虽然在facebook上获得的点赞数不多,但是也不排除会拍出一些好电影的可能性。
需要说明一定的是,在对于count较少的数据这里没有剔除,如果设置不同的噪音门槛得出的结论略有不同,特别是演员的趋势上,得出的结论会变化较大。
另外,本文的源码以及输出结果均已经上传到:
jijiwhywhy/IMDB-Analysis