Need to run this to generate csv files. May take a long time.


In [2]:
%matplotlib inline
from fenparsev4 import *
import pickle


Position(board='         \n         \n rnbqkbnr\n pppp.ppp\n ........\n ....p...\n ....P...\n .....N..\n PPPP.PPP\n RNBQKB.R\n         \n         ', score=0, wc=(True, True), bc=(True, True), ep=0, kp=0)
(93, 86)
(21, 91)
(96, 41), B->.

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


index error
index error
1000
2000
3000
index error
index error
index error
index error
4000
5000
index error
index error
index error
index error
index error
index error
6000
7000
index error
index error
index error
index error
8000
9000
10000
11000
index error
index error
index error
index error
index error
index error
index error
index error
index error
index error
index error
index error
12000
13000
14000
index error
15000
index error
index error
16000
17000
18000
index error
index error
19000
20000

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()


../data/csv_input/2015-12-07-csv1
converting x to list

In [109]:
df.shape


Out[109]:
(188314, 8)

In [ ]: