Exemplo n.º 1
0
def main(verbose=False,
         beta=0.05,
         prior_probability=0.5,
         epsilon=0.05,
         num_features=8,
         feature_cardinality=5,
         num_examples=100,
         visualization_interval=100,
         biased_feature_proportion=0.2,
         biased_feature_effect_length=10**100,
         directory="/tmp/adpredictor/",
         extension="png"):
    # Initialize globals
    np.random.seed(1)
    logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO)

    # Construct settings
    simulation = SimulationRunner.Simulation(
        predictor_config=AdPredictor.Config(
            beta=beta,
            prior_probability=prior_probability,
            epsilon=epsilon,
            num_features=num_features),
        feature_cardinality=feature_cardinality,
        num_examples=num_examples,
        directory=directory,
        biased_feature_proportion=biased_feature_proportion,
        biased_feature_effect_length=biased_feature_effect_length,
        visualization_interval=visualization_interval,
        extension=extension)

    # Train and output graphs
    simulation_runner = SimulationRunner(simulation)
    simulation_runner.run()
Exemplo n.º 2
0
def libsvm_file_process(config):
    adpredictor = AdPredictor(AdPredictor.Config(config.beta, config.epsilon),
                              config.feature_num)
    train_pred, train_label = [], []
    for train_file in config.train_files:
        for features, label in FileSampler(train_file).generate_samples():
            prob = adpredictor.train(features, label, True)
            train_pred.append(prob)
            train_label.append(1 if label > 0 else 0)
    adpredictor.save_model(config.model_file)
    test_pred, test_label = [], []
    for test_file in config.test_files:
        for features, label in FileSampler(test_file).generate_samples():
            prob = adpredictor.predict(features)
            test_pred.append(prob)
            test_label.append(1 if label > 0 else 0)
    return train_pred, train_label, test_pred, test_label, config
Exemplo n.º 3
0
 def _create_predictor(beta=0.05, prior=0.3, epsilon=0.01, num_features=10):
     config = AdPredictor.Config(beta, prior, epsilon, num_features)
     return AdPredictor(config)