relational learning )self rating_set rating_set self ratings rating_subset or rating_set training_ratings whichever is not empty if test_subset is noneself test_ratings self rating_set test_ratings elseself test_ratings test_subset self step_size step_size self reglz reglz self num_properties num_properties self num_ratings len(self ratingsself ave_rating (sum( for ( , , ,tin self ratings/self num_ratingsself users { for ( , , ,tin self ratingsself items { for ( , , ,tin self ratingsself user_bias { : for in self usersself item_bias { : for in self itemsself user_prop { :[random uniform(-property_range,property_rangefor in range(num_properties)for in self usersself item_prop { :[random uniform(-property_range,property_rangefor in range(num_properties)for in self itemsself zeros [ for in range(num_properties)self iter= def stats(self)self display( ,"ave sumsq error of mean for training="sum((self ave_rating-rating)** for (user,item,rating,timestampin self ratings)/len(self ratings)self display( ,"ave sumsq error of mean for test="sum((self ave_rating-rating)** for (user,item,rating,timestampin self test_ratings)/len(self test_ratings)self display( ,"error on training set"self evaluate(self ratings)self display( ,"error on test set"self evaluate(self test_ratings)learn carries out num iter steps of gradient descent relncollfilt py -(continued def prediction(self,user,item)"""returns prediction for this user on this item the use of get(is to handle users or items not in the training set ""return (self ave_rating self user_bias get(user, #self user_bias[userversion june