Example #1
0
def getTopProducts(doc_set, feature, dep_feature, num_products):
    ai = AttrInfo.lookup(feature)
    if ai is None:
        raise Exception("unknown feature: {0}".format(feature))

    mult = 1
    if ai.name == "price":
        mult = -1

    if not ai.is_discrete:
        buckets = bucketByPercentile(doc_set, feature, num_products)
        return filter(lambda x: x is not None, [
            argmax(b, lambda x: x.normalized[dep_feature], mult)
            for b in buckets
        ])

    else:
        bucketed = [
            filter(lambda x: x.normalized[feature] == v, doc_set)
            for v in ai.values
        ]
        prods = [
            argmax(b, lambda x: x.normalized[dep_feature], mult)
            for b in bucketed
        ]

        prods = filter(lambda x: x is not None, prods)
        return argmaxTake(prods, dep_feature, num_products, mult)
Example #2
0
def getTopProducts(doc_set, feature, dep_feature, num_products):
    ai = AttrInfo.lookup(feature)
    if ai is None:
        raise Exception("unknown feature: {0}".format(feature))

    mult = 1
    if ai.name == "price":
        mult = -1

    if not ai.is_discrete:
        buckets = bucketByPercentile(doc_set, feature, num_products)
        return filter(lambda x: x is not None,
                      [argmax(b, lambda x: x.normalized[dep_feature], mult) for b in buckets])

    else:
        bucketed = [filter(lambda x: x.normalized[feature] == v, doc_set) for v in ai.values]
        prods = [argmax(b, lambda x: x.normalized[dep_feature], mult) for b in bucketed]

        prods = filter(lambda x: x is not None, prods)
        return argmaxTake(prods, dep_feature, num_products, mult)