-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsudoku_data.py
31 lines (26 loc) · 997 Bytes
/
sudoku_data.py
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
# -*- coding: utf-8 -*-
"""sudoku_data.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1Nm6VofL0tUgUUvymSsMmvZgB-vfMXtwJ
"""
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
def normalize(game):
return game/9-0.5
def denormalize(game):
return (game+0.5)*9
def getSudokuData(file):
dataset = pd.read_csv(file, compression='zip', header=0, sep=',', quotechar='"').to_numpy()
features_dataset = dataset[0:,0]
targets_dataset = dataset[0:,1]
features = []
targets = []
for i in range(len(dataset)):
features.append([int(j) for j in dataset[i][0]])
targets.append( [int(j) for j in dataset[i][1]])
features = normalize(np.array(features).reshape(len(dataset),9,9,1))
targets = np.array(targets).reshape(len(dataset),81,1)-1
X_train, X_test, y_train, y_test = train_test_split(features, targets, test_size=0.2)
return (X_train,y_train), (X_test,y_test)