<commit_before>#!/usr/bin/env python

import sys
import random
from math import sqrt
from operator import add

from pyspark import SparkConf, SparkContext
from pyspark.mllib.recommendation import ALS


##########################################################################
# Helpers
##########################################################################

def parse_rating(line, sep=','):
    """
    Parses a rating line
    Returns: tuple of (random integer, (user_id, profile_id, rating))
    """
    fields = line.strip().split(sep)
    user_id = int(fields[0])  # convert user_id to int
    profile_id = int(fields[1])  # convert profile_id to int
    rating = float(fields[2])  # convert rated_id to int
    return random.randint(1, 10), (user_id, profile_id, rating)


def parse_user(line, sep=','):
    """
    Parses a user line
    Returns: tuple of (user_id, gender)
    """
    fields = line.strip().split(sep)
    user_id = int(fields[0])  # convert user_id to int
    gender = fields[1]
    return user_id, gender


def compute_rmse(model, data, n):
    """
    Compute RMSE (Root Mean Squared Error), or square root of the average value
        of (actual rating - predicted rating)^2
    """
    predictions = model.predictAll(data.map(lambda x: (x[0], x[1])))
    predictions_ratings = predictions.map(lambda x: ((x[0], x[1]), x[2])) \
      .join(data.map(lambda x: ((x[0], x[1]), x[2]))) \
      .values()
    return sqrt(predictions_ratings.map(lambda x: (x[0] - x[1]) ** 2).reduce(add) / float(n))


##########################################################################
# Main
##########################################################################

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print "Incorrect number of arguments, correct usage: dating_recommender.py [user_id] [match_gender]"
        sys.exit(-1)

    # Configure Spark
    conf = SparkConf().setMaster("local") \
                      .setAppName("Dating Recommender") \
                      .set("spark.executor.memory", "2g")
    sc = SparkContext(conf=conf)

    matchseeker = int(sys.argv[1])
    gender_filter = sys.argv[2]

    # Create ratings RDD of (randint, (user_id, profile_id, rating))<commit_msg>[mllib] Fix arg parse error in matchmaker<commit_after>#!/usr/bin/env python

import sys
import random
from math import sqrt
from operator import add

from pyspark import SparkConf, SparkContext
from pyspark.mllib.recommendation import ALS


##########################################################################
# Helpers
##########################################################################

def parse_rating(line, sep=','):
    """
    Parses a rating line
    Returns: tuple of (random integer, (user_id, profile_id, rating))
    """
    fields = line.strip().split(sep)
    user_id = int(fields[0])  # convert user_id to int
    profile_id = int(fields[1])  # convert profile_id to int
    rating = float(fields[2])  # convert rated_id to int
    return random.randint(1, 10), (user_id, profile_id, rating)


def parse_user(line, sep=','):
    """
    Parses a user line
    Returns: tuple of (user_id, gender)
    """
    fields = line.strip().split(sep)
    user_id = int(fields[0])  # convert user_id to int
    gender = fields[1]
    return user_id, gender


def compute_rmse(model, data, n):
    """
    Compute RMSE (Root Mean Squared Error), or square root of the average value
        of (actual rating - predicted rating)^2
    """
    predictions = model.predictAll(data.map(lambda x: (x[0], x[1])))
    predictions_ratings = predictions.map(lambda x: ((x[0], x[1]), x[2])) \
      .join(data.map(lambda x: ((x[0], x[1]), x[2]))) \
      .values()
    return sqrt(predictions_ratings.map(lambda x: (x[0] - x[1]) ** 2).reduce(add) / float(n))


##########################################################################
# Main
##########################################################################

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print "Incorrect number of arguments, correct usage: dating_recommender.py [user_id] [match_gender]"
        sys.exit(-1)

    # Configure Spark
    conf = SparkConf().setMaster("local") \
                      .setAppName("Dating Recommender") \
                      .set("spark.executor.memory", "2g")
    sc = SparkContext(conf=conf)

    matchseeker = int(sys.argv[1])
    gender_filter = sys.argv[2]

    # Create ratings RDD of (randint, (user_id, profile_id, rating))
{'fraction_non_alphanumeric': 0.25255669186305024, 'fraction_numerical': 0.011116051578479324, 'mean_word_length': 3.7407797681770285, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2643373', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1338, 'n_words': 357}