{"action":"created","issue":{"url":"https://api.github.com/repos/lmjohns3/theanets/issues/83","labels_url":"https://api.github.com/repos/lmjohns3/theanets/issues/83/labels{/name}","comments_url":"https://api.github.com/repos/lmjohns3/theanets/issues/83/comments","events_url":"https://api.github.com/repos/lmjohns3/theanets/issues/83/events","html_url":"https://github.com/lmjohns3/theanets/issues/83","id":91679432,"number":83,"title":"Why do I get this error message? IndexError: index 4 is out of bounds for axis 1 with size 4","user":{"login":"gribeiro2004","id":12591023,"avatar_url":"https://avatars.githubusercontent.com/u/12591023?v=3","gravatar_id":"","url":"https://api.github.com/users/gribeiro2004","html_url":"https://github.com/gribeiro2004","followers_url":"https://api.github.com/users/gribeiro2004/followers","following_url":"https://api.github.com/users/gribeiro2004/following{/other_user}","gists_url":"https://api.github.com/users/gribeiro2004/gists{/gist_id}","starred_url":"https://api.github.com/users/gribeiro2004/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gribeiro2004/subscriptions","organizations_url":"https://api.github.com/users/gribeiro2004/orgs","repos_url":"https://api.github.com/users/gribeiro2004/repos","events_url":"https://api.github.com/users/gribeiro2004/events{/privacy}","received_events_url":"https://api.github.com/users/gribeiro2004/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-06-29T03:03:07Z","updated_at":"2015-06-30T11:02:15Z","closed_at":null,"body":"import pandas as pd\r\nimport pandas.io.data\r\nimport numpy as np\r\nimport datetime\r\nimport theanets\r\nfrom sklearn import preprocessing\r\nimport matplotlib.pyplot as plt\r\n\r\n\r\nstart = datetime.date(1965, 1, 1)\r\nend = datetime.date(2015, 6, 24)\r\ntickers = ['KO','PEP','^GSPC']\r\n\r\n\r\ndef get(tickers, start, end):\r\n    def data(ticker):\r\n        return pd.io.data.DataReader(ticker,'yahoo', start, end)\r\n    datas = map(data, tickers)\r\n    return pd.concat(datas, keys = tickers, names=['Ticker', 'Date'])\r\n\r\n\r\nall_data = get(tickers, start, end) \r\n \r\n \r\ndef raw_data():\r\n    Adj_close = all_data[['Adj Close']].reset_index()\r\n    Adj_close = Adj_close.pivot('Date', 'Ticker', 'Adj Close')\r\n    Adj_close.columns = ['Adj Close KO', 'Adj Close PEP', 'Adj Close GSPC']\r\n    \r\n    Close = all_data[['Close']].reset_index()\r\n    Close = Close.pivot('Date', 'Ticker', 'Close')\r\n    Close.columns = ['Close KO', 'Close PEP', 'Close GSPC']\r\n    \r\n    High = all_data[['High']].reset_index()\r\n    High = High.pivot('Date', 'Ticker', 'High')\r\n    High.columns = ['High KO', 'High PEP', 'High GSPC']\r\n    High['High KO'] = High['High KO']*Adj_close['Adj Close KO']/Close['Close KO']\r\n    High['High PEP'] = High['High PEP']*Adj_close['Adj Close PEP']/Close['Close PEP']\r\n    High['High GSPC'] = High['High GSPC']*Adj_close['Adj Close GSPC']/Close['Close GSPC']\r\n    return Adj_close, High\r\n\r\nAdj_close, High = raw_data()\r\n\r\ndef X_y():\r\n    Adj_close5 = Adj_close.shift(5)/Adj_close\r\n    Adj_close5.columns = ['Adj Close KO5', 'Adj Close PEP5', 'Adj Close GSPC5']\r\n    Adj_close4 = Adj_close.shift(4)/Adj_close\r\n    Adj_close4.columns = ['Adj Close KO4', 'Adj Close PEP4', 'Adj Close GSPC4']\r\n    Adj_close3 = Adj_close.shift(3)/Adj_close\r\n    Adj_close3.columns = ['Adj Close KO3', 'Adj Close PEP3', 'Adj Close GSPC3']\r\n    Adj_close2 = Adj_close.shift(2)/Adj_close\r\n    Adj_close2.columns = ['Adj Close KO2', 'Adj Close PEP2', 'Adj Close GSPC2']\r\n    Adj_close1 = Adj_close.shift(1)/Adj_close\r\n    Adj_close1.columns = ['Adj Close KO1', 'Adj Close PEP1', 'Adj Close GSPC1']\r\n           \r\n    X = pd.merge(Adj_close5, Adj_close4, left_index=True,right_index=True)\r\n    X = pd.merge(X, Adj_close3, left_index=True, right_index=True)\r\n    X = pd.merge(X, Adj_close2, left_index=True, right_index=True)\r\n    X = pd.merge(X, Adj_close1, left_index=True, right_index=True)\r\n           \r\n    y0 = Adj_close['Adj Close KO']\r\n    y1 = High['High KO'].shift(-1)\r\n    y = (y1-y0)/y0\r\n    y = pd.DataFrame(y)\r\n    y.columns = ['Max Return']   \r\n    \r\n    Data = pd.merge(y, X, left_index=True, right_index=True)\r\n    Data = Data.dropna()\r\n    y = Data['Max Return']\r\n    y = pd.DataFrame(y)\r\n    y.columns = ['Max Return']   \r\n    X = Data.drop('Max Return', axis=1)    \r\n    return X, y, Data\r\n    \r\nX, y, Data = X_y()\r\n\r\nX = X.apply(lambda x:(x.astype(float) - min(x))/(max(x)-min(x)), axis = 0)\r\nX = X.values\r\nX=X.astype(np.float32)  \r\n\r\ny = y.values\r\ny[np.where(y>0.005)] = 1\r\ny[np.where((y<=0.005) & (y>=0))] = 2\r\ny[np.where((y>-0.005) & (y<0))] = 3\r\ny[np.where(y<-0.005)] = 4\r\ny=y.astype(np.int32)   \r\ny = y.ravel()\r\n\r\n\r\ndef split_data(X,y, slices):\r\n    datasets = {}\r\n    starts = np.floor(np.cumsum(len(X)*np.hstack([0,slices[:-1]])))\r\n    \r\n    slices = {'training': slice(starts[0], starts[1]),\r\n              'validation': slice(starts[1], starts[2]),\r\n              'test': slice(starts[2], None)}\r\n    data = X,y\r\n    def slice_data(data, sl):\r\n        return tuple(d[sl] for d in data)\r\n    for label in slices:\r\n        datasets[label] = slice_data(data, slices[label])\r\n    return datasets\r\n    \r\ndatasets = split_data(X,y,(0.6, 0.2, None))\r\n\r\n\r\nimport climate\r\nclimate.enable_default_logging()\r\n\r\nexp=theanets.Experiment(theanets.Classifier, layers=(15,2000,200,4), hidden_l1=0.1)\r\nexp.train(datasets['training'], datasets['validation'], optimize='sgd', learning_rate=0.01, momentum=0.5)\r\n\r\nX_test, y_test = datasets['test']\r\ny_pred = exp.network.classify(X_test)\r\n\r\nfrom sklearn.metrics import confusion_matrix\r\nprint(confusion_matrix(y_test, y_pred))\r\n\r\n\r\n  "},"comment":{"url":"https://api.github.com/repos/lmjohns3/theanets/issues/comments/117125680","html_url":"https://github.com/lmjohns3/theanets/issues/83#issuecomment-117125680","issue_url":"https://api.github.com/repos/lmjohns3/theanets/issues/83","id":117125680,"user":{"login":"gribeiro2004","id":12591023,"avatar_url":"https://avatars.githubusercontent.com/u/12591023?v=3","gravatar_id":"","url":"https://api.github.com/users/gribeiro2004","html_url":"https://github.com/gribeiro2004","followers_url":"https://api.github.com/users/gribeiro2004/followers","following_url":"https://api.github.com/users/gribeiro2004/following{/other_user}","gists_url":"https://api.github.com/users/gribeiro2004/gists{/gist_id}","starred_url":"https://api.github.com/users/gribeiro2004/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gribeiro2004/subscriptions","organizations_url":"https://api.github.com/users/gribeiro2004/orgs","repos_url":"https://api.github.com/users/gribeiro2004/repos","events_url":"https://api.github.com/users/gribeiro2004/events{/privacy}","received_events_url":"https://api.github.com/users/gribeiro2004/received_events","type":"User","site_admin":false},"created_at":"2015-06-30T11:02:15Z","updated_at":"2015-06-30T11:02:15Z","body":"Got it. Worked like a charm.\r\nThanks a lot!!!!!"}}