Libsvm solution for Tic-tac-toe games

Source: Internet
Author: User

I. Problem Description

A three-level game, also known as a well-known game player, has two players, one draw circle and one draw cross, and the first to draw a line to win. The problem now is that we know how to use machine learning to enable computers to automatically determine whether a given game is winning or losing. Each Board can have 9 grids, so each Board can have a 9-dimensional vector, 1 represents X,-1 represents a circle, 0 represents a space, and each Board has two possible states, to win or lose, you can use 1 to win or-1 to lose.

Game data can be obtained on this website: http://archive.ics.uci.edu/ml /. You can use 50% of them for training, and the remaining 50% for testing.

There are many solutions. Let's talk about the SVM method first, because there is a very useful tool libsvm.

Ii. SVM

SVM is a support vector machine used to solve classification problems. It is well applied in solving small samples and non-linear problems.

Iii. libsvm

Libsvm is an SVMAlgorithmTool software (http://archive.ics.uci.edu/ml ). Download to the local device without installation. The file contains a Windows folder, which contains executable files in the window.

1) Data processing. Libsvm uses a fixed format of data, and the obtained board data cannot be used directly.

Perform the following conversions: X, X, O, O, X, O, O, positive -----> 1

The first 1 indicates that this is the winner, and the last nine data pairs use nine feature values.

If there are more than 900 pieces of data, manual conversion will be crazy. Excel has special functions for conversion, but we have tried this. I use gvim, and several commands can be converted.

2) Data Scaling

Data is usually scaled to-1 to + 1, which is faster. Run svm-scale.exe.Program.

Because the selected data is from-1 to + 1, this step is skipped.

3) training data

Run the following command: SVM-tain data.txt model.txt.

Generate a model using the data file data.txt, which is stored in model.txt.

This process involves selecting core functions and parameters.

4) prediction data

Run the following command: SVM-predict testingdata.txt model.txt output.txt.

Testingdata.txtis the test data file, model.txtis the model file, and output.txt is the result output file.

Iv. Summary

For this problem, the best kernel model is linear kernel, which is better than the common RBF kernel. The reason may be that the first thing SVM needs to do is to map data from low-dimensional to high-dimensional, which is the problem of linear division but linear division, therefore, there is no need for ing. Therefore, the linear kernel can be used, while the RBF kernel may be small. However, if the parameter is selected, the RBF kernel can also achieve a high accuracy. We do not understand the core model, so we need to think more.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.