1
$\begingroup$

Dataset: https://www.kaggle.com/bryanpark/sudoku

I would like to create a neural network for this Dataset.

Feature:

X: [ '004300209005009001070060043006002087190007400050083000600000105003508690042910300' '040100050107003960520008000000000017000906800803050620090060543600080700250097100']

Output:

Y: [ '864371259325849761971265843436192587198657432257483916689734125713528694542916378' '346179258187523964529648371965832417472916835813754629798261543631485792254397186']

The zeros represent a blank box, and the data is a flattened grid of 9x9.

I tried using the following code, but I found out that the data needs a significant amount of preprocessing.

def preprocess():

data = pd.read_csv('Sudoku/sudoku.csv')
print('Data: ', data.head())

x = data[data.columns[0]].values
y = data[data.columns[1]].values

x = x.reshape(-1, 1)
y = y.reshape(-1, 1)

print('\nx: ', x[0])
print('\ny: ', y[0])

return x, y


x, y = preprocess()
train_x, test_x, train_y, test_y = train_test_split(x, y, test_size=0.2)

scl = StandardScaler()
train_x = scl.fit_transform(train_x)
train_y = scl.fit_transform(train_y)
test_x = scl.fit_transform(test_x)
test_y = scl.fit_transform(test_y)

model = Sequential()
model.add(Dense(100, input_dim=1, activation='relu'))
model.add(Dense(50, activation='relu'))
model.add(Dense(1, activation='linear'))
model.compile(optimizer='adam', loss='mean_squared_error')
model.fit(train_x, train_y, epochs=3, validation_split=0.1, verbose=2)

I would like to know how to work with this data and of course, also the structure of my neural network.

$\endgroup$
1
$\begingroup$

You need to convert this large list of strings to a numpy array containing lists of integers. Here is how you can get the data into the correct format for a neural network:

import pandas as pd
from numpy import array

def preprocess():

    data = pd.read_csv('sudoku.csv')

    x = data[data.columns[0]].values
    y = data[data.columns[1]].values

    x = x.reshape(-1, 1)
    y = y.reshape(-1, 1)

    x = array([list(map(int,set[0])) for set in x])
    y = array([list(map(int,set[0])) for set in y])

    return x, y

x, y = preprocess()

print('\nx: ', x[0])
print('\ny: ', y[0])

I haven't thought enough about the problem to advise on how best to go about solving it, but at least this should get you started on playing around with different methods. Be aware that it will take a minute or so to run, as the script is now converting a large amount of strings to integers.

$\endgroup$
0
$\begingroup$

here you can see a very good answer. For kaggle competition see kernels.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.