예제 #1
0
        public void Load(string sFileName, double dTrainSetSize)
        {
            Dictionary <RecommenderSystem.DatasetType, Tuple <Users, Items> > splittedData;

            Tuple <Users, Items> data = dataLoaderEngine.Load(sFileName);

            users = data.Item1;
            items = data.Item2;

            this.dsSize  = dataLoaderEngine.GetDataSetSize();
            splittedData = dataUtils.Split(dTrainSetSize, dsSize, data, DatasetType.Test, DatasetType.Train);

            trainUsers = splittedData[DatasetType.Train].Item1;
            trainItems = splittedData[DatasetType.Train].Item2;
            testUsers  = splittedData[DatasetType.Test].Item1;
            testItems  = splittedData[DatasetType.Test].Item2;

            double trainSize = Math.Round(dsSize * dTrainSetSize);

            splittedData = dataUtils.Split(dTrainSetSize, trainSize, new Tuple <Users, Items>(this.trainUsers, this.trainItems), DatasetType.Validation, DatasetType.Train);

            trainUsers      = splittedData[DatasetType.Train].Item1;
            trainItems      = splittedData[DatasetType.Train].Item2;
            validationUsers = splittedData[DatasetType.Validation].Item1;
            validationItems = splittedData[DatasetType.Validation].Item2;

            //calculate the overall average rating
            CalculateAverageRatingForTrainingSet();

            similarityEngine = new SimilarityEngine(trainUsers, MAX_SIMILAR_USERS, logger);  //TODO - check whether it should be train/test users
            evaluationEngine = new EvaluationEngine(averageTrainRating);

            predictionEngine.addModel(PredictionMethod.Cosine, new CollaborativeFilteringModel(trainUsers, trainItems, similarityEngine, new CosineMethod()));
            predictionEngine.addModel(PredictionMethod.Pearson, new CollaborativeFilteringModel(trainUsers, trainItems, similarityEngine, new PearsonMethod()));
            predictionEngine.addModel(PredictionMethod.Random, new CollaborativeFilteringModel(trainUsers, trainItems, similarityEngine, new RandomMethod()));

            itemBasedEngine = new ItemBasedEngine(trainItems); //TODO - check that we need to use test items...
        }