def T1(): ''' Tests basic functionality of MLPR ''' A = np.random.rand(32, 4) Y = np.random.rand(32, 1) a = MLPR([4, 4, 1], maxIter=16, name='mlpr1') a.fit(A, Y) a.score(A, Y) a.predict(A) return True
print(stockData2) print(scale(stockDataASC)) # to get only specific columns of data from a array use : # data[:, [1, 9]] where data is array and you want columns 1, 9 (index start from 0) # scale the stock data, volume to ease the calculations and fit within the data range # Number of neurons in the input layer # 4 neurons to indicate the candle stick doji patterns # 4 neurons to indicate the previous most tested highs which are greater than previous day closing prices # 4 neurons to indicate the previous most tested lows which are less than previous day closing prices # 5 neurons to indicate the previous day open, close, high and low prices, and volume i = 17 # Number of neurons in the output layer # 5 neurons to indicate the current day open, close, high and low prices and volume o = 5 #Number of neurons in the hidden layers h = 17 #The list of layer sizes layers = [i, h, h, h, h, h, h, h, h, h, o] mlpr = MLPR(layers, maxIter=1000, tol=0.40, reg=0.001, verbose=True) mlpr.fit() #Begin prediction yHat = mlpr.predict(A) #Plot the results mpl.plot(A, Y, c='#b0403f') mpl.plot(A, yHat, c='#5aa9ab') mpl.show()
#Number of neurons in the output layer o = 4 #Number of neurons in the hidden layers h = 4 #The list of layer sizes layers = [i, h, o] mlpr = MLPR(layers, maxIter = 10000, tol = 0.0010, reg = 0.001, verbose = True) #Length of the hold-out period n = len(A) nDays = int(round(n*.3)) #Learn the data mlpr.fit(A[0: (n - nDays)], Y[1:(n - nDays + 1)]) #Begin prediction yHat = mlpr.predict(A[0: (n - 1)]) #Plot the results # mPlotLib.plot(list(range(nDays - 1)), Y[(n-nDays + 1):, (0)].reshape(-1, 1), c='#b04fff') # mPlotLib.plot(list(range(nDays - 1)), yHat[:, (0)].reshape(-1, 1), c='#000000') # # # mPlotLib.plot(A[(n-nDays): (n-1)], yHat, c='#5aa9ab') # mPlotLib.show() # plot with various axes scales mPlotLib.figure(1) nDays = n # linear mPlotLib.subplot(221) mPlotLib.plot(list(range(nDays - 1)), Y[(n-nDays + 1):, (0)].reshape(-1, 1), c='#b04fff') mPlotLib.plot(list(range(nDays - 1)), yHat[:, (0)].reshape(-1, 1), c='#000000')