TensorFlow Machine Learning Cookbook Chapter 6 (or rather, tic-tac-toe)

Learning tic-tac-toe

Recipe 41

What and how do you learn in the first place? ?? : angel:

The learner is defined by 9 (model variables and operations ...) ~ 11 (loss function ...). 4 (using coordinate transformation ...) ~ 8 (one from the training set ...) is the preparation and making the training set (Isn't it too long and complicated to prepare?) Does base_tic_tac_toe_moves.csv on github omit the symmetric aspect?

In summary, the learner itself is normal,

Input x: Phase information (one-dimensional list with 9 elements) layer1 = sigmoid(A1x+b1) layer2 = A2layer1+b2 Teacher label y: Best move (any of integers 0-9) (How do you define that best move (unverified)) loss: hoge entropy of layer2 and y

Actually, some data is put into the learner as a set (it feels like that)

Mal

board[::-1]

Sort the list in reverse order. Reference 1: baby:

list(zip(*[board[6:9], board[3:6], board[0:3]]))

Nanikore is long. Also, isn't "\ *" used for variable length arguments? ?? : construction_worker: Reference 2 ~ 4 It seems that a is expanded by adding an asterisk "\ *" like * a.

I tried various things (I think the Lord could understand this)

asterisk.png

Let's take a look at the list (zip (* [board [6: 9], board [3: 6], board [0: 3]])) step by step.

asterisk2.png

To make it easier to see (... ☆)

def print_board(board): #The argument is a one-dimensional list
    print(' ' + str(board[0]) + ' | ' + str(board[1]) + ' | ' + str(board[2]))
    #print('__________')
    print(' ' + str(board[3]) + ' | ' + str(board[4]) + ' | ' + str(board[5]))
    #print('__________')
    print(' ' + str(board[6]) + ' | ' + str(board[7]) + ' | ' + str(board[8]))
    print('\n')

def make_board(board_2d): #Convert a two-dimensional list to one-dimensional
    return [value for item in board_2d for value in item]
    '''
    board_1d = []
    for item in board_2d:
        for value in item:
            board_1d.append(value)
    return board_1d
    '''

so

asterisk3.png

return [value for item in board_2d for value in item]

See ☆ above: man_with_turban: Can be rewritten with a for statement (although it will be longer)

reference

  1. [python] Reverse with slices! !!
  2. How do you do unzip in Python?
  3. Expanding the sequence with an asterisk
  4. Python Iterators and Generators

Recommended Posts

TensorFlow Machine Learning Cookbook Chapter 6 (or rather, tic-tac-toe)
TensorFlow Machine Learning Cookbook Chapter 2 Personally Clogged
TensorFlow Machine Learning Cookbook Chapter 3 Personally Clogged
Machine learning (TensorFlow) + Lotto 6
<Course> Machine Learning Chapter 6: Algorithm 2 (k-means)
[Language processing 100 knocks 2020] Chapter 6: Machine learning
<Course> Machine Learning Chapter 7: Support Vector Machine
100 Language Processing Knock 2020 Chapter 6: Machine Learning
[Reading Notes] Hands-on Machine Learning with Scikit-Learn, Keras, and TensorFlow Chapter 1
<Course> Machine Learning Chapter 3: Logistic Regression Model
Machine learning
<Course> Machine Learning Chapter 1: Linear Regression Model
<Course> Machine learning Chapter 4: Principal component analysis
<Course> Machine Learning Chapter 2: Nonlinear Regression Model
A story about simple machine learning using TensorFlow
Install the machine learning library TensorFlow on fedora23
[Memo] Machine learning
Machine learning classification
Machine Learning sample
Python learning memo for machine learning by Chainer from Chapter 2
Installation of TensorFlow, a machine learning library from Google