示例#1
0
    def test_error_train_on_run_apprec(self):
        config = Config()
        strategy = config.strategy
        config.strategy = 'mlbva'

        training_path = MachineLearningData.MACHINE_LEARNING_TRAINING
        MachineLearningData.MACHINE_LEARNING_TRAINING = "error.txt"

        result = apprec.run()

        config.strategy = strategy
        MachineLearningData.MACHINE_LEARNING_TRAINING = training_path

        self.assertEqual(apprec.ERROR_TRAIN, result)
示例#2
0
    def test_error_train_on_run_apprec(self):
        config = Config()
        strategy = config.strategy
        config.strategy = 'mlbva'

        training_path = MachineLearningData.MACHINE_LEARNING_TRAINING
        MachineLearningData.MACHINE_LEARNING_TRAINING = "error.txt"

        result = apprec.run()

        config.strategy = strategy
        MachineLearningData.MACHINE_LEARNING_TRAINING = training_path

        self.assertEqual(apprec.ERROR_TRAIN, result)
    def load(self):
        config = Config()
        short_options = 'hdvo:d:v:s:z:idvo:tdvo:b:n:cdvo'
        long_options = ['help', 'debug', 'verbose', 'strategy=',
                        'profile_size=', 'init', 'train', 'because',
                        'nrecommendation', 'contribute']
        try:
            opts, args = getopt.getopt(sys.argv[1:], short_options,
                                       long_options)
            self.options = opts
        except getopt.GetoptError as error:
            config.set_logger()
            logging.error('Bad syntax: {}'.format(str(error)))
            self.usage()
            sys.exit()

        for o, p in opts:
            if o in ('-h', '--help'):
                self.usage()
                sys.exit()
            elif o in ('-d', '--debug'):
                config.debug = 1
            elif o in ('-v', '--verbose'):
                config.verbose = 1
            elif o in ('-s', '--strategy'):
                config.strategy = p
            elif o in ('-z', '--profile_size'):
                config.profile_size = int(p)
            elif o in ('-i', '--init'):
                continue
            elif o in ('-t', '--train'):
                continue
            elif o in ('-b', '--because'):
                config.because = True
            elif o in ('-n', '--num-recommendations'):
                config.num_recommendations = int(p)
            elif o in ('-c', '--contribute'):
                continue
            else:
                assert False, "unhandled option"
示例#4
0
    cfg = Config()
    population_sample = []
    sample_file = sys.argv[2]
    sample_str = sample_file.split('/')[-1]
    with open(sample_file, 'r') as f:
        for line in f.readlines():
            user_id = line.strip('\n')
            population_sample.append(
                os.path.join(cfg.popcon_dir, user_id[:2], user_id))
    sample_dir = ("results/%s/%s" %
                  (strategy_category, sample_str))
    if not os.path.exists(sample_dir):
        os.makedirs(sample_dir)

    for strategy in strategies:
        cfg.strategy = strategy
        p_10_summary = {}
        f05_100_summary = {}
        c_10 = {}
        c_100 = {}

        log_file = os.path.join(sample_dir, sample_str + "-" + cfg.strategy)
        graph_10 = log_file + "-10.png"
        graph_100 = log_file + "-100.png"
        graph_10_jpg = graph_10.strip(".png") + ".jpg"
        graph_100_jpg = graph_100.strip(".png") + ".jpg"
        comment_10 = graph_10_jpg + ".comment"
        comment_100 = graph_100_jpg + ".comment"

        with open(comment_10, 'w') as f:
            f.write("# sample %s\n" % sample_str)
示例#5
0
    def load(self):
        config = Config()
        short_options = "hdvo:f:b:a:e:p:m:u:l:c:x:w:s:z:r:n:idvo:tdvo"
        long_options = ["help", "debug", "verbose", "output=", "filtersdir=",
                        "pkgsfilter=", "axi=", "dde=", "popconindex=",
                        "popcondir=", "indexmode=", "clustersdir=",
                        "kmedoids=", "maxpopcon=", "weight=", "strategy=",
                        "profile_size=", "profiling=", "neighbors=", "init",
                        "train"]
        try:
            opts, args = getopt.getopt(sys.argv[1:], short_options,
                                       long_options)
            self.options = opts
        except getopt.GetoptError as error:
            config.set_logger()
            logging.error("Bad syntax: %s" % str(error))
            self.usage()
            sys.exit()

        for o, p in opts:
            if o in ("-h", "--help"):
                self.usage()
                sys.exit()
            elif o in ("-d", "--debug"):
                config.debug = 1
            elif o in ("-v", "--verbose"):
                config.verbose = 1
            elif o in ("-o", "--output"):
                config.output = p
            elif o in ("-f", "--filtersdir"):
                config.filters_dir = p
            elif o in ("-b", "--pkgsfilter"):
                config.pkgs_filter = p
            elif o in ("-a", "--axi"):
                config.axi = p
            elif o in ("-e", "--dde"):
                config.dde_url = p
            elif o in ("-p", "--popconindex"):
                config.popcon_index = p
            elif o in ("-m", "--popcondir"):
                config.popcon_dir = p
            elif o in ("-u", "--index_mode"):
                config.index_mode = p
            elif o in ("-l", "--clustersdir"):
                config.clusters_dir = p
            elif o in ("-c", "--kmedoids"):
                config.k_medoids = int(p)
            elif o in ("-x", "--max_popcon"):
                config.max_popcon = int(p)
            elif o in ("-w", "--weight"):
                config.weight = p
            elif o in ("-s", "--strategy"):
                config.strategy = p
            elif o in ("-z", "--profile_size"):
                config.profile_size = int(p)
            elif o in ("-z", "--profiling"):
                config.profiling = p
            elif o in ("-n", "--neighbors"):
                config.k_neighbors = int(p)
            elif o in ("-i", "--init"):
                continue
            elif o in ("-t", "--train"):
                continue
            else:
                assert False, "unhandled option"
    # iterations = 3
    # content_based = ['cb']
    # collaborative = ['knn_eset']
    # hybrid = ['knnco']
    # profile_size = [50,100]
    # neighbors = [50]
    iterations = 20
    content_based = ['cb', 'cbt', 'cbd', 'cbh',
                     'cb_eset', 'cbt_eset', 'cbd_eset', 'cbh_eset']
    collaborative = ['knn_eset', 'knn', 'knn_plus']
    hybrid = ['knnco', 'knnco_eset']
    profile_size = [10, 20, 40, 60, 80, 100, 140, 170, 200, 240]
    neighbors = [3, 5, 10, 20, 30, 50, 70, 100, 150, 200]

    cfg = Config()
    cfg.strategy = sys.argv[1]

    # user =
    # PopconSystem("/root/.app-recommender/popcon-entries/4a/4a67a295ec14826db2aa1d90be2f1623")
    user = PopconSystem(
        "/root/.app-recommender/popcon-entries/8b/8b44fcdbcf676e711a153d5db09979d7")  # noqa
    # user = PopconSystem(sys.argv[1])
    user.filter_pkg_profile(cfg.pkgs_filter)
    user.maximal_pkg_profile()

    if cfg.strategy in content_based:
        run_content(user, cfg)
    if cfg.strategy in collaborative:
        run_collaborative(user, cfg)
    if cfg.strategy in hybrid:
        run_hybrid(user, cfg)
示例#7
0
    def load(self):
        config = Config()
        short_options = "hdvo:f:b:a:e:p:m:u:l:c:x:w:s:z:r:n:idvo:tdvo"
        long_options = [
            "help", "debug", "verbose", "output=", "filtersdir=",
            "pkgsfilter=", "axi=", "dde=", "popconindex=", "popcondir=",
            "indexmode=", "clustersdir=", "kmedoids=", "maxpopcon=", "weight=",
            "strategy=", "profile_size=", "profiling=", "neighbors=", "init",
            "train"
        ]
        try:
            opts, args = getopt.getopt(sys.argv[1:], short_options,
                                       long_options)
            self.options = opts
        except getopt.GetoptError as error:
            config.set_logger()
            logging.error("Bad syntax: %s" % str(error))
            self.usage()
            sys.exit()

        for o, p in opts:
            if o in ("-h", "--help"):
                self.usage()
                sys.exit()
            elif o in ("-d", "--debug"):
                config.debug = 1
            elif o in ("-v", "--verbose"):
                config.verbose = 1
            elif o in ("-o", "--output"):
                config.output = p
            elif o in ("-f", "--filtersdir"):
                config.filters_dir = p
            elif o in ("-b", "--pkgsfilter"):
                config.pkgs_filter = p
            elif o in ("-a", "--axi"):
                config.axi = p
            elif o in ("-e", "--dde"):
                config.dde_url = p
            elif o in ("-p", "--popconindex"):
                config.popcon_index = p
            elif o in ("-m", "--popcondir"):
                config.popcon_dir = p
            elif o in ("-u", "--index_mode"):
                config.index_mode = p
            elif o in ("-l", "--clustersdir"):
                config.clusters_dir = p
            elif o in ("-c", "--kmedoids"):
                config.k_medoids = int(p)
            elif o in ("-x", "--max_popcon"):
                config.max_popcon = int(p)
            elif o in ("-w", "--weight"):
                config.weight = p
            elif o in ("-s", "--strategy"):
                config.strategy = p
            elif o in ("-z", "--profile_size"):
                config.profile_size = int(p)
            elif o in ("-z", "--profiling"):
                config.profiling = p
            elif o in ("-n", "--neighbors"):
                config.k_neighbors = int(p)
            elif o in ("-i", "--init"):
                continue
            elif o in ("-t", "--train"):
                continue
            else:
                assert False, "unhandled option"