brunch

매거진 Spark+Python

You can make anything
by writing

C.S.Lewis

by 보나벤투라 Nov 12. 2017

평점데이터 탐색

http://files.grouplens.org/datasets/movielens/ml-100k.zip

실습 데이터 : 사용자들이 영화에 대해 매긴 점수와 관련된 100k 데이터 집합

[root@client_server ~]# vi $SPARK_HOME/conf/spark-env.sh

export PYSPARK_DRIVER_PYTHON=/root/anaconda3/envs/py35/bin/ipython3

[root@client_server ~]# $SPARK_HOME/bin/pyspark --master spark://master:7077

pyspark를 아이 파이썬 콘솔 기능으로 사용 가능!



평점별 빈도 분포 탐색

>> import numpy as np

>> import matplotlib.pyplot as plt

>> import seaborn as sns

>> rdd=sc.textFile("dataset/ml-100k/u.data")

>> rdd.take(1) #check sep="\t"

>> rating_data=rdd.map(lambda x : x.split("\t"))

>> rating=rating_data.map(lambda x:(x[2],1)).reduceByKey(lambda x,y:x+y).collect()

>> x_axis1=np.array([c[0] for c in rating])

>> y_axis1=np.array([int(c[1]) for c in rating]) #change type to be int to calculate after

>> x_axis=x_axis1[np.argsort(x_axis1)] #Ascending sort by x_axis

>> y_axis=y_axis1[np.argsort(x_axis1)]/y_axis1.sum() #normalize y_axis to percentages

>> position=np.arange(len(x_axis))

>> ax=plt.axes()

>> ax.set_xticks(position)

>> ax.set_xticklabels(x_axis)

>> plt.xticks(rotation=30)

>> plt.bar(position,y_axis,width=1.0,color='lightblue')

>> fig=plt.gcf()

>> fig.show()

영화의 평점은 4점이 가장 많다
관람자별 평점 준 횟수 분포 탐색

>> rdd=sc.textFile("dataset/ml-100k/u.data")

>> rdd.take(1) #sep="\t"

>> rating_data=rdd.map(lambda x : x.split("\t"))

>> rating_num_by_user=rating_data.map(lambda x:x[0]).countByValue() #number of ratings by user

>> user=list(dict(rating_num_by_user).keys()) #change keys of dict to be list 

>> num=list(dict(rating_num_by_user).values()) #change values of dict to be list

>> position=np.arange(len(user))

>> plt.axes().set_xticks(np.arange(0,len(user),100)) #separate user num range by 100 units

>> plt.axes().set_xticklabels(user)

>> plt.xticks(rotation=30)

>> plt.bar(position,num,width=1.0,color='lightblue')

>> plt.show()

탐색을 통해 얻은 결과


평점별 빈도 분포 탐색

: 영화들이 받은 평점은 3,4점이 가장 많다. 하지만 1,2점은 정말 적다. 

[꼬리 분석질문] "이 현상은 보통 이상의 평점을 주고싶은 사람들의 성향에 기인하는 것일까? 또는 개봉했던 영화들이 실로 우수한 평가를 받았던 것일까?" 


- 관람자별 평점 준 횟수 분포 탐색 

: 특정 사람들은, 영화를 아주 많이 관람하고 있다. 

[꼬리 분석질문] "이들은 누구이며, 어떤 특성을 지닐까?"

매거진의 이전글 영화데이터 탐색

작품 선택

키워드 선택 0 / 3 0

댓글여부

afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari