sample python script create dataset for neural networks
this script just for testing (test on ml.net)
for use need to upgrade and fix
you need to modify to fit as you use
my test on ml.net use binary to 1 and 0 get result better than number (Dec)
test 1
datasetNN1.py
import random
import time
from bit import Key
import math
timestr = time.strftime("%Y%m%d-%H%M%S")
filename = "datasetNN_" + str(timestr) + ".csv"
print(time.strftime("%Y-%m-%d-%H:%M:%S"))
print(filename)
feature = ""
f = open(filename, "w")
j = 1
while j <= 256:
#print(j)
feature = feature + "f" + str(j) + ","
j += 1
header = feature+"Lebel"
#print(header)
f.write(header+"\n")
f.close()
i = 1
while i < 1000:
#while i < 1000000:
#label_output = '0'
label_output = 'even'
#print(i)
seed = random.randrange(2**119,2**120)
#seed = random.randrange(2**256)
key = Key.from_int(seed)
address = key.address
pubkey = key.public_key.hex()
x,y = key.public_point
if y % 2 == 0:
#label_output = 0 # even
#label_output = 'even' # even
label_output = 1 # even
else:
#label_output = 1 # odd
#label_output = 'odd' # odd
label_output = 2 # odd
y2_bin = bin(y)[2:]
bin2_split = list(y2_bin)
if len(bin2_split) == 256:
feature_binary = ""
for x in range(len(bin2_split)):
feature_binary = feature_binary + bin2_split[x] + ","
adddataline = feature_binary + str(label_output)
#print(addline)
f = open(filename, "a")
f.write(adddataline+"\n")
f.close()
i += 1
print(time.strftime("%Y-%m-%d-%H:%M:%S"))
test 2
datasetNN2.py
import random
import time
from bit import Key
import math
timestr = time.strftime("%Y%m%d-%H%M%S")
filename = "datasetNN_" + str(timestr) + ".csv"
print(time.strftime("%Y-%m-%d-%H:%M:%S"))
print(filename)
feature = ""
f = open(filename, "w")
j = 1
#while j <= 256:
while j <= 64:
#print(j)
#feature = feature + "f" + str(j) + ","
feature = feature + "x" + str(j) + ","
j += 1
header = feature+"Lebel"
#print(header)
f.write(header+"\n")
f.close()
i = 1
while i < 1000:
#while i < 1000000:
#label_output = '0'
label_output = 'even'
#print(i)
seed = random.randrange(2**119,2**120)
#seed = random.randrange(2**256)
key = Key.from_int(seed)
address = key.address
pubkey = key.public_key.hex()
x,y = key.public_point
if y % 2 == 0:
#label_output = 0 # even
#label_output = 'even' # even
label_output = 1 # even
else:
#label_output = 1 # odd
#label_output = 'odd' # odd
label_output = 2 # odd
#y2_bin = bin(y)[2:]
#bin2_split = list(y2_bin)
bin2_split = list(pubkey[2:])
#if len(bin2_split) == 256:
#if len(pubkey) == 64:
feature_hex = ""
for x in range(len(bin2_split)):
#feature_hex = feature_hex + bin2_split[x] + ","
hex2_num = int(bin2_split[x], 16)
feature_hex = feature_hex + str(hex2_num) + ","
adddataline = feature_hex + str(label_output)
#print(addline)
f = open(filename, "a")
f.write(adddataline+"\n")
f.close()
i += 1
print(time.strftime("%Y-%m-%d-%H:%M:%S"))