Source code for mmlspark.recommendation.RankingEvaluator

# Copyright (C) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in project root for information.


import sys
if sys.version >= '3':
    basestring = str

from pyspark.ml.param.shared import *
from pyspark import keyword_only
from pyspark.ml.util import JavaMLReadable, JavaMLWritable
from mmlspark.core.serialize.java_params_patch import *
from pyspark.ml.evaluation import JavaEvaluator
from pyspark.ml.common import inherit_doc
from mmlspark.core.schema.Utils import *

[docs]@inherit_doc class RankingEvaluator(ComplexParamsMixin, JavaMLReadable, JavaMLWritable, JavaEvaluator): """ Args: itemCol (str): Column of items k (int): number of items (default: 10) labelCol (str): label column name (default: label) metricName (str): metric name in evaluation (ndcgAt|map|precisionAtk|recallAtK|diversityAtK|maxDiversity|mrr|fcp) (default: ndcgAt) nItems (long): number of items (default: -1) predictionCol (str): prediction column name (default: prediction) ratingCol (str): Column of ratings userCol (str): Column of users """ @keyword_only def __init__(self, itemCol=None, k=10, labelCol="label", metricName="ndcgAt", nItems=-1, predictionCol="prediction", ratingCol=None, userCol=None): super(RankingEvaluator, self).__init__() self._java_obj = self._new_java_obj("com.microsoft.ml.spark.recommendation.RankingEvaluator") self.itemCol = Param(self, "itemCol", "itemCol: Column of items") self.k = Param(self, "k", "k: number of items (default: 10)") self._setDefault(k=10) self.labelCol = Param(self, "labelCol", "labelCol: label column name (default: label)") self._setDefault(labelCol="label") self.metricName = Param(self, "metricName", "metricName: metric name in evaluation (ndcgAt|map|precisionAtk|recallAtK|diversityAtK|maxDiversity|mrr|fcp) (default: ndcgAt)") self._setDefault(metricName="ndcgAt") self.nItems = Param(self, "nItems", "nItems: number of items (default: -1)") self._setDefault(nItems=-1) self.predictionCol = Param(self, "predictionCol", "predictionCol: prediction column name (default: prediction)") self._setDefault(predictionCol="prediction") self.ratingCol = Param(self, "ratingCol", "ratingCol: Column of ratings") self.userCol = Param(self, "userCol", "userCol: Column of users") if hasattr(self, "_input_kwargs"): kwargs = self._input_kwargs else: kwargs = self.__init__._input_kwargs self.setParams(**kwargs)
[docs] @keyword_only def setParams(self, itemCol=None, k=10, labelCol="label", metricName="ndcgAt", nItems=-1, predictionCol="prediction", ratingCol=None, userCol=None): """ Set the (keyword only) parameters Args: itemCol (str): Column of items k (int): number of items (default: 10) labelCol (str): label column name (default: label) metricName (str): metric name in evaluation (ndcgAt|map|precisionAtk|recallAtK|diversityAtK|maxDiversity|mrr|fcp) (default: ndcgAt) nItems (long): number of items (default: -1) predictionCol (str): prediction column name (default: prediction) ratingCol (str): Column of ratings userCol (str): Column of users """ if hasattr(self, "_input_kwargs"): kwargs = self._input_kwargs else: kwargs = self.__init__._input_kwargs return self._set(**kwargs)
[docs] def setItemCol(self, value): """ Args: itemCol (str): Column of items """ self._set(itemCol=value) return self
[docs] def getItemCol(self): """ Returns: str: Column of items """ return self.getOrDefault(self.itemCol)
[docs] def setK(self, value): """ Args: k (int): number of items (default: 10) """ self._set(k=value) return self
[docs] def getK(self): """ Returns: int: number of items (default: 10) """ return self.getOrDefault(self.k)
[docs] def setLabelCol(self, value): """ Args: labelCol (str): label column name (default: label) """ self._set(labelCol=value) return self
[docs] def getLabelCol(self): """ Returns: str: label column name (default: label) """ return self.getOrDefault(self.labelCol)
[docs] def setMetricName(self, value): """ Args: metricName (str): metric name in evaluation (ndcgAt|map|precisionAtk|recallAtK|diversityAtK|maxDiversity|mrr|fcp) (default: ndcgAt) """ self._set(metricName=value) return self
[docs] def getMetricName(self): """ Returns: str: metric name in evaluation (ndcgAt|map|precisionAtk|recallAtK|diversityAtK|maxDiversity|mrr|fcp) (default: ndcgAt) """ return self.getOrDefault(self.metricName)
[docs] def setNItems(self, value): """ Args: nItems (long): number of items (default: -1) """ self._set(nItems=value) return self
[docs] def getNItems(self): """ Returns: long: number of items (default: -1) """ return self.getOrDefault(self.nItems)
[docs] def setPredictionCol(self, value): """ Args: predictionCol (str): prediction column name (default: prediction) """ self._set(predictionCol=value) return self
[docs] def getPredictionCol(self): """ Returns: str: prediction column name (default: prediction) """ return self.getOrDefault(self.predictionCol)
[docs] def setRatingCol(self, value): """ Args: ratingCol (str): Column of ratings """ self._set(ratingCol=value) return self
[docs] def getRatingCol(self): """ Returns: str: Column of ratings """ return self.getOrDefault(self.ratingCol)
[docs] def setUserCol(self, value): """ Args: userCol (str): Column of users """ self._set(userCol=value) return self
[docs] def getUserCol(self): """ Returns: str: Column of users """ return self.getOrDefault(self.userCol)
[docs] @classmethod def read(cls): """ Returns an MLReader instance for this class. """ return JavaMMLReader(cls)
[docs] @staticmethod def getJavaPackage(): """ Returns package name String. """ return "com.microsoft.ml.spark.recommendation.RankingEvaluator"
@staticmethod def _from_java(java_stage): module_name=RankingEvaluator.__module__ module_name=module_name.rsplit(".", 1)[0] + ".RankingEvaluator" return from_java(java_stage, module_name)