Example #1
0
def predict(examples):

    # 1. Crear modelo
    print('(CLASSIFIER) Creating model...')
    model = Model()

    # 2. Cargar clasificador
    print('(CLASSIFIER) Loading model...')
    model.load()

    # 3. Calcular prediccion
    prediction = model.predict(examples)
    print('(CLASSIFIER) Prediction obtained (' + str(prediction) + ')')

    return prediction
Example #2
0
def analyze(company):
    """ This route responds when the user submits how many models they would like to train.
        It trains and predicts with a model as many times as the user specified and then
        redirects to the final results page.
        
        Parameters:
            company(str): stock symbol of the stock that the model will analyze
    """

    # Reads the user's submission of how many models they would like to train and sets
    # it to 1 if the user entered something besides a positive integer
    try:
        count = int(request.form['count'])
        if (count <= 0 or count > 3):
            count = 1
    except ValueError:
        count = 1

    # Reading the data stored locally and then cleaning out the filesystem
    X_pred = pd.read_csv('prediction_data.csv')
    x = pd.read_csv('x.csv')
    y = pd.read_csv('y.csv')
    os.remove('prediction_data.csv')
    os.remove('x.csv')
    os.remove('y.csv')

    # Stores the final prediction and error of each model after it has
    # completed all of the epochs of traing
    predictions = []
    errors = []

    # Stores the predictions each model makes after each epoch
    prediction_json = []

    for i in range(0, count):

        reg = Model(len(x.columns))

        prediction_history, rmse = reg.train(x, y, X_pred)

        prediction_history.insert(0, 'Model ' + str(i + 1))
        prediction_json.append(prediction_history)

        Y_pred = reg.predict(X_pred)
        predictions.append(Y_pred)
        errors.append(rmse)

    # Average the predictions to get the final or "true" prediction/error
    true_prediction = sum(predictions) / len(predictions)
    true_error = sum(errors) / len(errors)

    # Saving result data so that it can be used in the next route
    session['predictions'] = prediction_json
    session['true_prediction'] = true_prediction
    session['true_error'] = true_error

    print('')
    print('********************')
    print('TRUE PREDICTION: ' + str(true_prediction))
    print('********************')
    print('')
    print('True Error: ' + str(true_error))
    print('')

    return redirect('/' + company + '/' + str(count) + '/' 'results')