Python Forum

Full Version: Need help with Python + Neural Net Coding
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
A very good day to you Sir,

I hope you are doing Great Sir,

I downloaded Run.py and Create.py from the internet.

I would like to use the Run.Py to read data from the_results.txt data file.

The Range of Data should be from 1 to 58 and not 1 to 68

May I please kindly ask how can I set the Run.py to only read from the range of data 1 to 58 ?

And not 1 to 69 as per the original code ?

Thank you very much for your time and kind help.

You'll need to install Anaconda Python 2.7, neurolab library, numpy library and termcolor library

Create.py

import neurolab as nl
net = nl.net.newff([[0,1]] * 69, [69,69])
net.save("one.net")
Run.py

from colorama import init
init()

import neurolab as nl
import numpy as np
from termcolor import colored

#read inputs and targets
f = open("the_results.txt",'r')
input = []
line_count = 0
for line in f.readlines():
 line = line.split(',')
 line_count += 1
 if line_count > 1: #skip line 1
  
  lineinput = [0] * 69
  #for i in range(1,6):
   #lineinput[int(line[i])-1] = 1
  input.append(lineinput)
input.reverse() #powerball shows results in reverse order from newest to oldest so we will reverse this list

#set target outputs for training to be from row 1 to end of list, skipping first row 0
target = input[1:len(input)]
#set siminput to be last row of input to use for simulation to predict output
siminput = [input[len(input)-1]]

#set input, make input one row less since the last row wouldn't have target output
input = input[0:len(input)-1]


#make it numpy
target = np.array(target)
input = np.array(input)
siminput = np.array(siminput)


def output(o):
 array = o[0]
 order = array.argsort()
 #ranks = order.argsort()
 
 for i in range(57,-1,-1):
  index = order[i] + 1
  print colored(str(index),"green") + colored("(" + str(int(array[index-1] * 1000)/1000.0) + ")","red"),
  if i % 5 == 0:
   print
 print 
 
net = nl.load("one.net")
print colored("Powerball","blue") + colored(" number","green") + colored("(probability)","red")
out = net.sim(siminput)
output(out)
while True:
 net = nl.load("one.net")
 print "Training..."




 error = net.train(input,target,epochs=3,show=1)




 
 # with line below we can specify training to stop when error[0] is smaller than goal it stops
 # but since we're inside a forever loop, there's no need to specify goal.
 # error = net.train(input,target,epochs=10,show=1,goal=0.01)
 
 # just a fail safe, just an extra save so that if we Ctrl-C while we're saving we'll have at least copy of latest network that works
 net.save("one.net.bk")
 net.save("one.net")
 
 print colored("Powerball","blue") + colored(" number","green") + colored("(probability)","red")
 out = net.sim(siminput)
 
 #output for display purposes only
 output(out)

The_Results.txt


04,07,09,34,35,53
10,15,23,28,50,53
20,21,23,29,49,56
12,29,31,34,35,39
07,10,14,15,16,26
21,25,27,33,37,46
08,11,13,19,21,24
06,14,16,33,46,58
03,08,21,22,27,57
04,19,21,30,32,46
10,12,41,42,45,51
07,09,27,30,34,54
07,08,24,38,39,54
02,07,26,28,29,30
15,21,44,47,51,55
11,20,38,52,53,55
21,30,41,43,52,58
05,11,15,27,53,58
06,42,44,46,53,57
03,11,37,44,45,47
09,34,36,52,53,55
10,19,29,34,35,54