예제 #1
0
파일: data.py 프로젝트: CSP197/numerox
 def y_to_nan(self):
     """Copy of data with y values set to NaN"""
     data = self.copy()
     for name in nx.tournament_names(active_only=True):
         kwargs = {name: np.nan}
         data.df = data.df.assign(**kwargs)
     return data
예제 #2
0
def tournament_str2int(tournament_str):
    "Convert tournament name (as str) to tournament integer"
    if tournament_str not in nx.tournament_names(active_only=True):
        raise ValueError('`tournament_str` name not recognized')
    for tourney in TOURNAMENTS:
        if tourney['name'] == tournament_str:
            return tourney['number']
    raise RuntimeError("Did not find tournament number")
예제 #3
0
def tournament_str(tournament_int_or_str):
    "Convert tournament int or str to str"
    if nx.isstring(tournament_int_or_str):
        if tournament_int_or_str not in nx.tournament_names(active_only=True):
            raise ValueError('tournament name is unknown')
        return tournament_int_or_str
    elif nx.isint(tournament_int_or_str):
        return tournament_int2str(tournament_int_or_str)
    raise ValueError('input must be a str or int')
예제 #4
0
def tournament_str(tournament_int_or_str):
    """Convert tournament int or str to str"""
    if nx.isstring(tournament_int_or_str):
        if tournament_int_or_str not in nx.tournament_names(active_only=False):
            raise ValueError('tournament name is not recognized')
        return tournament_int_or_str
    elif nx.isint(tournament_int_or_str):
        return tournament_int2str(tournament_int_or_str)
    raise ValueError('input must be a str or int')
예제 #5
0
 def __init__(self,
              training_config: str,
              competition: str = 'numerai',
              submit: bool = False):
     self.training_config = training_config
     self.competition = competition
     self.submit = submit
     self.tourament_names = nx.tournament_names()
     self.load_trainer_params
     self.setup_trainers
     self.setup_data
예제 #6
0
def predict_and_submit(data, model_class):
    model_name = model_class.__name__
    model_id = model_class.model_id
    logger = logging.getLogger(model_name)

    for tournament in nx.tournament_names():

        logger.info(f"Predict and submit for {tournament} using {model_class}")
        saved_model_name = f'model_trained_{model_name}_{tournament}'
        if os.path.exists(saved_model_name):
            logger.info(f'Using saved model {saved_model_name}')
            m = model_class.load(saved_model_name)
        else:
            logger.info(f'Saved model {saved_model_name} not found')
            m = model_class(verbose=True)

            try:
                logger.info(
                    f'Training model against {tournament} training data')
                m.fit(data['train'], tournament)
            except Exception as e:
                logger.error(f'Failed to train {model_class} - {e}')
                return

        # fit model with train data and make predictions for tournament data
        logger.info(f'Predicting with {model_class} on {tournament} data')
        prediction = nx.production(m, data, tournament=tournament)

        # save predictions to csv file
        prediction_filename = f'/tmp/prediction_{model_name}_{tournament}.csv'
        logger.info(f"Saving predictions to {prediction_filename}")
        prediction.to_csv(prediction_filename, verbose=True)

        try:
            # submit the prediction
            logger.info(
                f"Submitting predictions from {prediction_filename} using {model_id}"
            )
            submission_id, status = nx.upload(prediction_filename,
                                              tournament,
                                              NUMERAI_PUBLIC_ID,
                                              NUMERAI_SECRET_KEY,
                                              block=False,
                                              n_tries=N_TRIES,
                                              sleep_seconds=SLEEP_SECONDS,
                                              model_id=model_id)
            logger.info(status)
            logger.info(
                f'Successfully submitted predictions using model_id {model_id}'
            )
        except Exception as e:
            logger.error(f'Upload failed with - {e}')
예제 #7
0
def train(data, model_class):
    model_name = model_class.__name__

    for tournament_name in nx.tournament_names():
        saved_model_name = f'model_trained_{model_name}_{tournament_name}'

        # create your model
        m = model_class(verbose=True)

        logger.info(f'Fitting {model_name} for {saved_model_name}')
        m.fit(data['train'], tournament_name)

        logger.info(f'Saving {model_name} for {saved_model_name}')
        m.save(saved_model_name)
def train():
    tournaments = nx.tournament_names()
    print(tournaments)

    # download dataset from numerai
    data = nx.download('numerai_dataset.zip')

    for tournament_name in tournaments:
        # create your model
        m = model.LogisticModel(verbose=True)

        print("fitting model for", tournament_name)
        m.fit(data['train'], tournament_name)

        print("saving model for", tournament_name)
        m.save('model_trained_' + tournament_name)
예제 #9
0
def predict():

    tournaments = nx.tournament_names()
    print(tournaments)

    # download dataset from numerai
    data = nx.download('numerai_dataset.zip', load=False)
    print('data downloaded')
    data = nx.load_zip('numerai_dataset.zip', single_precision=True)
    print('data loaded')

    for tournament_name in tournaments:
        saved_model_name = 'model_trained_' + tournament_name
        if os.path.exists(saved_model_name):
            print("using saved model for", tournament_name)
            m = model.LinearModel.load(saved_model_name)
        else:
            print("saved model not found for", tournament_name)
            m = model.LinearModel(verbose=True)

            print("training model for", tournament_name)
            m.fit(data['train'], tournament_name)

        print("running predictions for", tournament_name, flush=True)
        # fit model with train data and make predictions for tournament data
        prediction = nx.production(m, data, tournament=tournament_name)

        # save predictions to csv file
        prediction_filename = '/tmp/prediction_' + tournament_name + '.csv'
        prediction.to_csv(prediction_filename, verbose=True)

    # submit the prediction

    # Numerai API key
    # You will need to create an API key by going to https://numer.ai/account and clicking "Add" under the "Your API keys" section.
    # Select the following permissions for the key: "Upload submissions", "Make stakes", "View historical submission info", "View user info"
    public_id = os.environ["NUMERAI_PUBLIC_ID"]
    secret_key = os.environ["NUMERAI_SECRET_KEY"]

    for tournament_name in tournaments:
        prediction_filename = '/tmp/prediction_' + tournament_name + '.csv'

        api = NumerAPI(public_id=public_id, secret_key=secret_key)
        model_id = api.get_models()
        api.upload_predictions(prediction_filename,
                               model_id=model_id['akrimedes_2'])
def predict_and_submit():
    # Numerai API key
    # You will need to create an API key by going to https://numer.ai/account and clicking "Add" under the "Your API keys" section.
    # Select the following permissions for the key: "Upload submissions", "Make stakes", "View historical submission info", "View user info"
    public_id = os.environ["NUMERAI_PUBLIC_ID"]
    secret_key = os.environ["NUMERAI_SECRET_KEY"]

    tournaments = nx.tournament_names()
    print(tournaments)

    # download dataset from numerai
    data = nx.download('numerai_dataset.zip')

    for tournament_name in tournaments:
        saved_model_name = 'model_trained_' + tournament_name
        if os.path.exists(saved_model_name):
            print("using saved model for", tournament_name)
            m = model.LogisticModel.load(saved_model_name)
        else:
            print("saved model not found for", tournament_name)
            m = model.LogisticModel(verbose=True)

            print("training model for", tournament_name)
            m.fit(data['train'], tournament_name)

        print("running predictions for", tournament_name)
        # fit model with train data and make predictions for tournament data
        prediction = nx.production(m, data, tournament=tournament_name)

        # save predictions to csv file
        prediction_filename = '/tmp/prediction_' + tournament_name + '.csv'
        prediction.to_csv(prediction_filename, verbose=True)

    # submit the prediction
    for tournament_name in tournaments:
        prediction_filename = '/tmp/prediction_' + tournament_name + '.csv'

        submission_id = nx.upload(prediction_filename,
                                  tournament_name,
                                  public_id,
                                  secret_key,
                                  block=False)
예제 #11
0
import numerox as nx
import numerapi
import os
import model

tournaments = nx.tournament_names()
print(tournaments)

data = nx.download('numerai_dataset.zip', load=False)

print('hello')