Exemplo n.º 1
0
def test02():
    print("Test 02")

    rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescTheMostPopular(
    )
    recommenderID: str = InputRecomRRDefinition.THE_MOST_POPULAR

    rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescKNN()
    recommenderID: str = InputRecomRRDefinition.KNN

    rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescBPRMFIMPL(
    )
    recommenderID: str = InputRecomRRDefinition.BPRMFIMPL

    rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescVMContextKNN(
    )
    recommenderID: str = InputRecomRRDefinition.VMC_KNN

    rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescCosineCB(
    )
    recommenderID: str = InputRecomRRDefinition.COSINECB

    rDescr: RecommenderDescription = InputRecomRRDefinition.exportRDescW2V()
    recommenderID: str = InputRecomRRDefinition.W2V

    pDescr: Portfolio1MethDescription = Portfolio1MethDescription(
        recommenderID.title(), recommenderID, rDescr)

    dataset: ADataset = DatasetRetailRocket.readDatasetsWithFilter(
        minEventCount=50)

    behavioursDF: DataFrame = BehavioursRR.readFromFileRR(
        BehavioursRR.getFile("static08"))

    history: AHistory = HistoryDF("test")
    p: APortfolio = pDescr.exportPortfolio("jobID", history)
    p.train(history, dataset)

    argsSimulationDict: Dict[str, str] = {
        SimulationRR.ARG_WINDOW_SIZE: 50,
        SimulationRR.ARG_RECOM_REPETITION_COUNT: 1,
        SimulationRR.ARG_NUMBER_OF_RECOMM_ITEMS: 100,
        SimulationRR.ARG_NUMBER_OF_AGGR_ITEMS:
        InputSimulatorDefinition.numberOfAggrItems,
        SimulationRR.ARG_DIV_DATASET_PERC_SIZE: 90,
        SimulationRR.ARG_HISTORY_LENGTH: 10
    }

    # simulation of portfolio
    simulator: Simulator = Simulator("test", SimulationRR, argsSimulationDict,
                                     dataset, behavioursDF)
    simulator.simulate([pDescr], [DataFrame()], [EToolDoNothing({})],
                       [HistoryHierDF("a")])
def test12():
    print("Test 12")

    print("Running Recommender BPRMF on RR:")
    from datasets.retailrocket.events import Events  # class

    batchID: str = "batchID"

    trainDataset: ADataset
    testDataset: ADataset
    trainDataset, testDataset = DatasetRetailRocket.readDatasetsWithFilter(
        50).divideDataset(90)

    testUserIDs: ndarray = testDataset.eventsDF[Events.COL_VISITOR_ID].unique()

    history: AHistory = HistoryHierDF(["aa"])

    numberOfItems: int = 20

    rd: RecommenderDescription = InputRecomRRDefinition.exportRDescBPRMFIMPL()
    #rd:RecommenderDescription = InputRecomRRDefinition.exportRDescBPRMF()
    #rd:RecommenderDescription = InputRecomRRDefinition.exportRDescTheMostPopular()
    rd: RecommenderDescription = InputRecomRRDefinition.exportRDescKNN()
    #rd:RecommenderDescription = InputRecomRRDefinition.exportRDescCosineCBcbdOHEupsweightedMeanups3()
    #rd:RecommenderDescription = InputRecomRRDefinition.exportRDescW2Vtpositivei50000ws1vs32upsweightedMeanups3()
    #rd:RecommenderDescription = InputRecomRRDefinition.exportRDescW2Vtpositivei50000ws1vs64upsweightedMeanups7()

    r: ARecommender = rd.exportRecommender("aaa")
    argumentsDict: Dict = rd.getArguments()

    r.train(history, trainDataset)

    numberOfHit: int = 0
    for userIdI in testUserIDs[0:500]:
        recI: Series = r.recommend(int(userIdI), numberOfItems, argumentsDict)
        recItemIDsI: List[int] = [i for i in recI.keys()]

        windowItemIds: List[int] = testDataset.eventsDF.loc[
            testDataset.eventsDF[Events.COL_VISITOR_ID] == userIdI][
                Events.COL_ITEM_ID].unique()
        itemIdsHitted: List[int] = list(set(recItemIDsI) & set(windowItemIds))
        numberOfHit += len(itemIdsHitted)

    print("")
    print("numberOfHit: " + str(numberOfHit))
            counter += len(intersectionI)

        print("  counter: " + str(counter))


if __name__ == "__main__":
    os.chdir("..")

    dataset: ADataset = DatasetRetailRocket.readDatasetsWithFilter(
        minEventCount=50)

    rDscrTheMostPopular: RecommenderDescription = InputRecomRRDefinition.exportRDescTheMostPopular(
    )
    rDscrItemBasedKNN: RecommenderDescription = InputRecomRRDefinition.exportRDescKNN(
    )
    rDscrBPRMF: RecommenderDescription = InputRecomRRDefinition.exportRDescBPRMFIMPL(
    )
    rDscrVMContextKNN: RecommenderDescription = InputRecomRRDefinition.exportRDescVMContextKNN(
    )
    rDscrCosineCB: RecommenderDescription = InputRecomRRDefinition.exportRDescCosineCB(
    )
    rDscrW2V: RecommenderDescription = InputRecomRRDefinition.exportRDescW2V()

    rDscrs: List[object] = [
        rDscrTheMostPopular, rDscrItemBasedKNN, rDscrBPRMF, rDscrVMContextKNN,
        rDscrCosineCB, rDscrW2V
    ]
    rDscrs: List[object] = [rDscrW2V]

    for rDscrI in rDscrs:
        se: StaticEvaluation = StaticEvaluation(dataset)
        se.evaluate(rDscrI)