O'Reilly logo

Machine Learning with Spark - Second Edition by Nick Pentreath, Manpreet Singh Ghotra, Rajdeep Dua

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exploring the user dataset

First, we will analyze the characteristics of MovieLens users.

We use a custom_schema to load the | delimited data into a DataFrame. This Python code is in com/sparksamples/Util.py:

def get_user_data():   custom_schema = StructType([   StructField("no", StringType(), True),   StructField("age", IntegerType(), True),   StructField("gender", StringType(), True),   StructField("occupation", StringType(), True),   StructField("zipCode", StringType(), True) ]) frompyspark.sql import SQLContext frompyspark.sql.types import * sql_context = SQLContext(sc) user_df = sql_context.read    .format('com.databricks.spark.csv')    .options(header='false', delimiter='|')    .load("%s/ml-100k/u.user"% PATH, schema =  custom_schema) returnuser_df ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required