本文使用Zeppelin和Hive对MovieLens电影数据集进行分析,包括电影流行度分析、口碑分析等。
Zeppelin连接Hive请参考:
Zeppelin组件配置和使用:使用JDBC连接Hive
MovieLens数据集介绍请参考:
MovieLens数据集(电影推荐、Hive、Spark SQL)
数据集介绍
本文选择MovieLens小数据集ml-1m包含100万评分数据集,下载地址
http://files.grouplens.org/datasets/movielens/ml-1m.zip
数据集包括包括用户、评分和电影三个文件,数据格式和示例如下
(1)用户信息(6040) users.dat
userid:gender:age:occupation:zipcode
1::F::1::10::48067
(2)电影信息(3952) movies.dat
movieid:moviename:movietype
1::Toy Story (1995)::Animation|Children's|Comedy
(3)评分信息(1000209) ratings.dat
userid:movieid:rating:timestamp
1::1193::5::978300760
将数据上传至HDFS
hdfs dfs -mkdir /movie
hdfs dfs -put users.dat movies.dat ratings.dat /movie
hdfs dfs -ls /movie
创建数据库
create database movie;
use movie;
创建数据表并加载数据
(1)创建用户表
create table t_user(
userid bigint,
sex string,
age int,
occupation string,
zipcode string)
row format serde 'org.apache.hadoop.hive.serde2.RegexSerDe'
with serdeproperties('input.regex'='(.*)::(.*)::(.*)::(.*)::(.*)','output.format.string'='%1$s %2$s %3$s %4$s %5$s')
stored as textfile;
加载数据
load data inpath "/movie/users.dat" into table t_user;
(2)创建电影表
create table t_movie(
movieid bigint,
moviename string,
movietype string)
row format serde 'org.apache.hadoop.hive.serde2.RegexSerDe'
with serdeproperties('