Poker Prediction Using Neural Network
|
Task I:
Testing the task1:
In order to test dataset for this task please change the
testfilename= "test_data_TA.csv"
to your test file (this is available in the beginning of the code). After running the program, it will save the output to “output_task1.csv”.
Algorithm idea:
Testing the task1:
In order to test dataset for this task please change the
testfilename= "test_data_TA.csv"
to your test file (this is available in the beginning of the code). After running the program, it will save the output to “output_task1.csv”.
Algorithm idea:
There are two steps training for our algorithm using neural network backpropagation. Both network using tanh activation function which will be explained below.
StandardScaler function:
Using sklearn.preprocessing.StandardScaler
Standardize features by removing the mean and scaling to unit variance
Activation function for the hidden layer:
the hyperbolic tan function f(x) = tanh(x) for activation
Backpropagation Algorithm
we define the cost function with respect to that single example to be:
- raw data S1,R1,S2,R2…S5,R5 are used and standardized by the StandardScaler function.
- Train the neural network using backpropagation algorithm. The first neural network has
- The prediction 1 is served as one of input features for second neural network. Other features including odd or even, prime property and equality are standardized by the StandardScaler function.
- Train the second neural network using backpropagation algorithm. The second neural network has 200x100x50 neurons 3 hidden layers. The accuracy goes to 0.969 finally.
StandardScaler function:
Using sklearn.preprocessing.StandardScaler
Standardize features by removing the mean and scaling to unit variance
Activation function for the hidden layer:
the hyperbolic tan function f(x) = tanh(x) for activation
Backpropagation Algorithm
we define the cost function with respect to that single example to be:
Task 2:
Testing the task2:
In order to test this task you only need to call main() function.
In order to test dataset for this task please change the
input_for_task_2 = "test_data_TA.csv"
to your test file (this is available in the beginning of the code). After running the program, it will save the output to “output_task2.csv”. Each function has a brief explanation under the comment, and some important features of function has explanation (You can find explanation in boxes covered by ‘#’). I tried to reduce the complexity and readability as much as possible so I divided the task to many functions. These are all the functions that we used in this task: feature_extract(), data_process(), prediction(), open_the_input_file(), make_all_combination(), main().
Algorithms
The prediction function is similar to two steps prediction function in task 1.
For task 2, given one hand, the nested for loop creates 4(suits)*13(rank)*5(cards)-repetition = 236 new cards. Basically by changing one card in a hand we generate 235 new cards and the card itself.
Then prediction the task 2 using two steps prediction for Hand and choose the highest score set.
Function:
feature(): the MLPClassifier does a good job in predicting but for some hands (such as 9, 8, 7) we don’t have enough training data to teach our neural network. So we found some features in data and we use them to improve our prediction. This function provides those features. The output is a list with new features
data_process(): this function is from TASK I. Detailed explanation is available there.
prediction(): this is same as in TASK I.
open_the_input_file(): This function opens a csv file in reading mode. Reads each line saves them to a list. Then using list.append() makes a list of lists (a matrix). Returns the created list.
make_all_combination(): The input is a list. This function copies the list to a new list. We are given one hand, the nested for loop creates 4(suits)*13(rank)*5(cards)-repetition = 236 new cards. Basically by changing one card in a hand we generate 235 new cards and the card itself. The return of the function is a list that contains all this cards.
main(): main function does not have any input or output but it calls all the function mentioned above. First it calls open_the_input_file() to open and read the input file. Then it opens the output file in writing mode. Here we use a for loop to change each card, predict the hand, choose the maximum among all prediction and write the changed card to output file.
Testing the task2:
In order to test this task you only need to call main() function.
In order to test dataset for this task please change the
input_for_task_2 = "test_data_TA.csv"
to your test file (this is available in the beginning of the code). After running the program, it will save the output to “output_task2.csv”. Each function has a brief explanation under the comment, and some important features of function has explanation (You can find explanation in boxes covered by ‘#’). I tried to reduce the complexity and readability as much as possible so I divided the task to many functions. These are all the functions that we used in this task: feature_extract(), data_process(), prediction(), open_the_input_file(), make_all_combination(), main().
Algorithms
The prediction function is similar to two steps prediction function in task 1.
For task 2, given one hand, the nested for loop creates 4(suits)*13(rank)*5(cards)-repetition = 236 new cards. Basically by changing one card in a hand we generate 235 new cards and the card itself.
Then prediction the task 2 using two steps prediction for Hand and choose the highest score set.
Function:
feature(): the MLPClassifier does a good job in predicting but for some hands (such as 9, 8, 7) we don’t have enough training data to teach our neural network. So we found some features in data and we use them to improve our prediction. This function provides those features. The output is a list with new features
data_process(): this function is from TASK I. Detailed explanation is available there.
prediction(): this is same as in TASK I.
open_the_input_file(): This function opens a csv file in reading mode. Reads each line saves them to a list. Then using list.append() makes a list of lists (a matrix). Returns the created list.
make_all_combination(): The input is a list. This function copies the list to a new list. We are given one hand, the nested for loop creates 4(suits)*13(rank)*5(cards)-repetition = 236 new cards. Basically by changing one card in a hand we generate 235 new cards and the card itself. The return of the function is a list that contains all this cards.
main(): main function does not have any input or output but it calls all the function mentioned above. First it calls open_the_input_file() to open and read the input file. Then it opens the output file in writing mode. Here we use a for loop to change each card, predict the hand, choose the maximum among all prediction and write the changed card to output file.