Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algorithm works as expected when dataframe is reversed by date #4

Open
behdadahmadi opened this issue Oct 10, 2018 · 0 comments
Open

Comments

@behdadahmadi
Copy link

Hi, I try your scripts and get 50% AUC. If I try it with reversed dataframe,it will works as expected as your results. Did I do something false in my codes?

import pandas as pd
import numpy as np
from Score import auc
from sklearn.ensemble import RandomForestClassifier,AdaBoostClassifier,VotingClassifier
from sklearn.metrics import accuracy_score,classification_report
def MakeDataframe(csv,reverse):
    df = pd.read_csv(csv)
    if reverse:
        df = df[::-1]
    df = df[['open','close']]
    #print df.head(12)
    return df.values

def Window(dataset):
    dataX,dataY = [],[]
    for i in range(len(dataset) - 9):
        item = dataset[i:(i+10),0:2]
        item = item.ravel()
        if item[19] >= item[18]:
            target = 1
        else:
            target = 0
        dataY.append(target)
        item = item[:19]
        item = item / item[0]
        dataX.append(item)

    return np.array(dataX), np.array(dataY)

reverse = True
train = MakeDataframe('./CSV/EURUSD-2016-10-1W_1M.csv',reverse)
test = MakeDataframe('./CSV/EURUSD-2016-10-2W_1M.csv',reverse)

X,Y = Window(train)
X_test,Y_test = Window(test)

Y = Y.astype('int')
Y_test = Y_test.astype('int')
model = RandomForestClassifier(n_jobs=-1,n_estimators=100,oob_score=True,verbose=False)
#model2 = AdaBoostClassifier()

#model = VotingClassifier([('RF',model1),('Ada',model2)],n_jobs=-1,voting='soft')
model.fit(X,Y)

Y_pred = model.predict_proba(X_test)[:,1]
predicted = model.predict(X_test)
score = accuracy_score(Y_test,predicted)
report = classification_report(Y_test,predicted)
print score
print auc(Y_test,Y_pred)
print report
print model.oob_score_

I also attach two CSV files I used in the script.

Thank you so much and best regards

CSV.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant