Recommendation Engines mit PySpark erstellen
Jamen Long
Data Scientist at Nike
F. Maxwell Harper und Joseph A. Konstan. 2015
The MovieLens Datasets: History and Context.
ACM Transactions on Interactive Intelligent Systems (TiiS) 5, 4, Artikel 19 (Dezember 2015), 19 Seiten.
DOI=http://dx.doi.org/10.1145/2827872
F. Maxwell Harper und Joseph A. Konstan. 2015
The MovieLens Datasets: History and Context.
ACM Transactions on Interactive Intelligent Systems (TiiS) 5, 4, Artikel 19 (Dezember 2015), 19 Seiten.
DOI=http://dx.doi.org/10.1145/2827872
Bewertungen: 20.000.000+
Nutzer:innen: 138.493
Filme: 27.278
df.show()
df.columns()

# Anzahl Bewertungen in der Matrix
numerator = ratings.count()
# Unterschiedliche Nutzer und Filme
users = ratings.select("userId").distinct().count()
movies = ratings.select("movieId").distinct().count()
# Anzahl Bewertungen in der Matrix numerator = ratings.count() # Unterschiedliche Nutzer und Filme users = ratings.select("userId").distinct().count() movies = ratings.select("movieId").distinct().count()# Anzahl möglicher Bewertungen ohne leere Zellen denominator = users * movies
# Anzahl Bewertungen in der Matrix
numerator = ratings.count()
# Unterschiedliche Nutzer und Filme
users = ratings.select("userId").distinct().count()
movies = ratings.select("movieId").distinct().count()
# Anzahl möglicher Bewertungen ohne leere Zellen
denominator = users * movies
# Sparsität berechnen
sparsity = 1 - (numerator*1.0 / denominator)
print ("Sparsity: "), sparsity
Sparsity: .998
ratings.select("userId").distinct().count()
671
# Gruppieren nach userId
ratings.groupBy("userId")
# Anzahl der Song-Abspielungen pro userId
ratings.groupBy("userId").count().show()
+------+-----+
|userId|count|
+------+-----+
| 148| 76|
| 243| 12|
| 31| 232|
| 137| 16|
| 251| 19|
| 85| 752|
| 65| 737|
| 255| 9|
| 53| 190|
| 133| 302|
| 296| 74|
| 78| 301|
| 108| 136|
| 155| 3|
| 193| 174|
| 101| 1|
+------+-----+
from pyspark.sql.functions import min, max, avg
# Minimale Anzahl an Song-Abspielungen pro userId
msd.groupBy("userId").count()
.select(min("count")).show()
+----------+
|min(count)|
+----------+
| 1|
+----------+
# Maximale Anzahl an Song-Abspielungen pro userId
ratings.groupBy("userId").count()
.select(max("count")).show()
+----------+
|max(count)|
+----------+
| 1162|
+----------+
# Durchschnittliche Anzahl an Song-Abspielungen pro userId
ratings.groupBy("userId").count()
.select(avg("count")).show()
+----------+
|avg(count)|
+----------+
| 233.34579|
+----------+
# Entfernt Nutzer mit weniger als 20 Bewertungen
ratings.groupBy("userId").count().filter(col("count") >= 20).show()
+------+-----+
|userId|count|
+------+-----+
| 148| 76|
| 31| 232|
| 85| 752|
| 65| 737|
| 53| 190|
| 133| 302|
| 296| 74|
| 78| 301|
| 108| 136|
| 193| 174|
+------+-----+
Recommendation Engines mit PySpark erstellen