Hi! Can someone help me fix this python code! I don't know why their is a syntax error on print colored. I need this tomorrow so please bless me with the Christmas love and spirit by helping me.
Here's the whole code:
Here is the display output error:
Of course happy holidays!
Here's the whole code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import neurolab as nl import numpy as np from termcolor import colored #read inputs and targets f = open ( "megamillions.csv" , 'r' ) input = [] line_count = 0 for line in f.readlines(): line = line.split( ',' ) line_count + = 1 if line_count > 0 : #don't skip line 1 lineinput = [ 0 ] * 75 for i in range ( 4 , 9 ): lineinput[ int (line[i]) - 1 ] = 1 input .append(lineinput) #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 ( 74 , - 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( "Mega Million" , "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 = 10 ,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( "Mega Million" , "blue" ) + colored( " number" , "green" ) + colored( "(probability)" , "red" ) out = net.sim(siminput) #output for display purposes only output(out) |
Error:File "C:/Users/Yip/Desktop/MEGA_NN/run.py", line 41
print colored(str(index),"green") + colored("(" + str(int(array[index-1] * 1000)/1000.0) + ")","red"),
^
SyntaxError: invalid syntax
Thanks so much to anyone willing to help with great knowledge of python!Of course happy holidays!