Need to run this to generate csv files. May take a long time.
In [2]:
%matplotlib inline
from fenparsev4 import *
import pickle
In [3]:
def fen2csv(fen_filename, blocksize=1000, debug=True):
#read in fen file
with open(fen_filename) as f:
content = [" ".join(line.split(" ")[:2]) for line in f.readlines()]
#each generated file has about 2500 instances, with 5 legal and 5 illegal per board
n = blocksize #"block" size
i = 72000 # current location
j = 72 # current iteration
while (i < len(content)):
#read in n fens
df = fen2mlinput(content[i:i+n])
i += n
j += 1
if debug: print(i)
df.to_csv('/media/drive/storage/csv_input/2015-12-08_112mil' + str(j))
In [ ]:
import os
#most important part
def fries_ready():
os.system('say your fries are done')
#read in fen file
fen2csv("/media/drive/storage/2015-12-08_112mil.fens")
#fries_ready()
In [61]:
#p
#each generated file has about 2500 instances, with 5 legal and 5 illegal per board
n = 1000
i = 0
j = 0
while (i < len(content)):
#read in n fens
df = fen2mlinput(content[i:i+n])
i += n
j += 1
print(i)
df.to_csv('../data/csv_input/2015-12-07-csv' + str(j))
#print(df.shape)
#write to file
In [116]:
#returns dataframe with certain columns converted back to lists/integers
def unpickle_csv(filename_prefix='../data/csv_input/2015-12-07-csv', filename_suffix_range=range(1,21), debug=True):
#read in csv
df = pd.DataFrame()
for i in filename_suffix_range:
if debug: print(filename_prefix + str(i))
df = df.append(pd.read_csv(filename_prefix + str(i)))
#clean columns
df['y'] = df['y'].astype(int)
if debug: print("converting x to list")
df['x'] = df['x'] = df.loc[:, 'x'].apply(lambda x: [1 if '1' == a else 0 for a in x.split(', ')])
#reindex
length = df.shape[0]
df = df.set_index([range(0,length)])
return df;
df = unpickle_csv('../data/csv_input/2015-12-07-csv', range(1,2))
df.head()
fries_ready()
In [109]:
df.shape
Out[109]:
In [ ]: