예제 #1
0
def run_numerai_batch():

    # Get Reference to Properties
    config = configparser.ConfigParser()
    config.read('C:\etc\properties.ini')

    # Numerai credentials for submission
    public = config['numerai']['public']
    secret = config['numerai']['secret']

    # compute the tournament numer
    week = time.strftime("%U")
    contest = str(int(week) + 245)

    print("\n Numerai Contest..." + contest)

    # Work out directory and create if not exists
    directory = 'F:\\Numerai\\numerai' + contest + '\\'

    first = "FALSE"

    if not os.path.exists(directory):

        first = "TRUE"

        # Make new Dir
        os.makedirs(directory)

        # download dataset from numerai, save it and then load it
        nx.download(directory + 'numerai_dataset.zip')

        # Unzip it
        with ZipFile(directory + 'numerai_dataset.zip', 'r') as zipObj:

            #Extract all the contents of zip file in current directory
            zipObj.extractall(directory)

    # Run my xg boost algo on it
    rvalue = str(mechXg.main(contest))
    #rvalue = str(0.041)

    #if not first == "TRUE" :
    if not first == "FALSE":

        # Tweet
        print("Tweeting ..")
        Tweet.tweetSomething(
            'Happy New Year! I am uploading submission for numer.ai [' +
            contest + '] with correlation [' + rvalue + '] ')

        # Upload to numerai
        print("Uploading")
        names = ('nomi', )
        for name in names:
            nxj.upload(directory + name + '_submission.csv', name, public,
                       secret)

    print("All Done")
예제 #2
0
def numerox_example():
    
    config = configparser.ConfigParser()
    config.read('C:\etc\properties.ini') 
    
    public = config['numerai']['public']
    secret = config['numerai']['secret']
    
    
    """
    Example of how to prepare a submission for the Numerai tournament.
    It uses Numerox which you can install with: pip install numerox
    For more information see: https://github.com/kwgoodman/numerox
    """
    
    #contest = str(165)
    #contest = str(config['numerai']['tournament'])
    week = time.strftime("%U")
    contest = str(int(week) + 140)

    directory = 'F:\\Numerai\\numerai' + contest + '\\'

    if not os.path.exists(directory):
        os.makedirs(directory)

        # download dataset from numerai, save it and then load it
        # data = nx.download(directory + 'numerai_dataset.zip')
        nx.download(directory + 'numerai_dataset.zip')

        with ZipFile(directory + 'numerai_dataset.zip', 'r') as zipObj:
            #Extract all the contents of zip file in current directory
            zipObj.extractall(directory)

    # we will use logistic regression; you will want to write your own model
    # model = nx.logistic()

    # fit model with train data and make predictions for tournament data
    #prediction = nx.production(model, data, tournament='bernie')

    # save predictions to csv file
    # prediction.to_csv('logistic.csv', verbose=True)

    mechXg.main(contest)

    # upload predictions to Numerai to enter the tournament
    # create the public_id and secret_key on the Numerai website
    #
    # nx.upload('logistic.csv', tournament='bernie', public_id, secret_key)

    names = ('bernie', 'ken', 'charles', 'frank', 'hillary') 
    #names = ('hillary',)     
    
    for name in names:

        nx.upload(directory + name + '_new_submission.csv', name, public, secret)
예제 #3
0
 def get_tournament_data() -> nx.data.Data:
     try:
         data: nx.data.Data = nx.download('numerai_dataset.zip')
     except Exception as e:
         LOGGER.info(f'Failure to download numerai data with {e}')
         raise e
     return data
예제 #4
0
def first_tournament():
    """
    Example of how to prepare a submission for the Numerai tournament.
    It uses Numerox which you can install with: pip install numerox
    For more information see: https://github.com/kwgoodman/numerox
    """

    # download dataset from numerai
    nx.download('numerai_dataset.zip', verbose=True)

    # load numerai dataset
    data = nx.load_zip('numerai_dataset.zip', verbose=True)

    # we will use logistic regression; you will want to write your own model
    model = nx.logistic()

    # fit model with train data and make predictions for tournament data
    prediction = nx.production(model, data)

    # save predictions to csv file
    prediction.to_csv('logistic.csv', verbose=True)
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)
예제 #6
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 numerox_example():
    """
    Example of how to prepare a submission for the Numerai tournament.
    It uses Numerox which you can install with: pip install numerox
    For more information see: https://github.com/kwgoodman/numerox
    """

    # download dataset from numerai, save it and then load it
    data = nx.download('numerai_dataset.zip')

    # we will use logistic regression; you will want to write your own model
    model = nx.logistic()

    # fit model with train data and make predictions for tournament data
    prediction = nx.production(model, data, tournament='bernie')

    # save predictions to csv file
    prediction.to_csv('logistic.csv', verbose=True)
예제 #8
0
def numerox_example():
    """
    Example of how to prepare a submission for the Numerai tournament.
    It uses Numerox which you can install with: pip install numerox
    For more information see: https://github.com/kwgoodman/numerox
    """

    # download dataset from numerai, save it and then load it
    data = nx.download('numerai_dataset.zip')

    # we will use logistic regression; you will want to write your own model
    model = nx.linear()

    # fit model with train data and make predictions for tournament data
    prediction = nx.production(model, data, tournament='kazutsugi')

    # save predictions to csv file
    prediction.to_csv('linear.csv', verbose=True)
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)
예제 #10
0
import numpy as np
import pandas as pd
import time
import os as os
import numerox as nx
from numpy import loadtxt
import xgboost as xgb
from xgboost import XGBRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn import linear_model, model_selection
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import GridSearchCV

os.chdir(os.path.join(os.getcwd()))
data = nx.download("numerai_dataset.zip")


#xgboost setup
class xgboost(nx.Model):
    def __init__(self, params):
        self.p = params

    #   if not HAS_XGBOOST:
    #      raise ImportError("You must install xgboost to use this model")

    def fit_predict(self, dfit, dpre):
        model = xgb.XGBRegressor(learning_rate=self.p['learning_rate'],
                                 subsample=self.p['subsample'],
                                 max_depth=self.p['max_depth'],
                                 n_estimators=self.p['n_estimators'],
예제 #11
0
    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)


if __name__ == '__main__':
    logger.info('Downloading dataset')
    data = nx.download('numerai_dataset.zip')

    # Or load dataset locally from file
    #data = nx.load_zip('numerai_datasets.zip', include_train=True, single_precision=True)

    # Train your models
    for model_class in model.models:
        try:
            train(data, model_class)
        except Exception as e:
            logger.error(f'Failed to train model {model_class} - {e}')
            raise

예제 #12
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')