LoginSignup
2
2

More than 3 years have passed since last update.

七対子と国士無双と四暗刻と断么九の打牌の特徴を主成分分析した

Last updated at Posted at 2020-07-11

概要

七対子と国士無双の打牌の特徴を主成分分析したに四暗刻と断么九を追加した。
データ数は同じく5000個ずつである。

結果

ニューラルネットワークの結果

各エージェントの打牌をニューラルネットワークで予測したときの精度を示す。
全て中間層は100次元で、手牌は170次元である。

エージェント名 精度
七対子 約60%
国士無双 約71%
四暗刻 約15%
断么九 約68%

主成分分析の結果

第一主成分と第二主成分の散布図

4class.png

累積寄与率

4class_ruiseki.png

寄与度

4class_kiyodo.png

作成したプログラム

# coding: UTF-8
import numpy as np
import matplotlib.pyplot as plt
import sklearn #機械学習のライブラリ
from sklearn.decomposition import PCA #主成分分析器
from pandas import plotting 
import matplotlib.ticker as ticker
import pandas as pd
from sklearn.preprocessing import StandardScaler


data = 5000

chitoi = np.loadtxt("C:/Users/p-user/Desktop/csvdata/chitoi_pca.csv")
chitoi = np.delete(chitoi,slice(data,None),0)
kokushi = np.loadtxt("C:/Users/p-user/Desktop/csvdata/kokushi_pca.csv")
kokushi = np.delete(kokushi,slice(data,None),0)
suanko = np.loadtxt("C:/Users/p-user/Desktop/csvdata/suanko_pca.csv")
suanko = np.delete(suanko,slice(data,None),0)
tanyao = np.loadtxt("C:/Users/p-user/Desktop/csvdata/tanyao_pca.csv")
tanyao = np.delete(tanyao,slice(data,None),0)

df1 = np.vstack((chitoi,kokushi))
df2 = np.vstack((df1,suanko))
df  = np.vstack((df2,tanyao))
#print(df.shape)

"""
lavel = np.zeros((data*4))
for i in range(data,len(lavel)):
    if 5000 <= i <=10000:
        lavel[i] = 1
    elif 10001 <= i <= 15000:
        lavel[i] = 2
    elif 15001 <= i <= 20000:
        lavel[i] = 3
"""

pca = PCA()
feature = pca.fit(df)
# データを主成分空間に写像
feature = pca.transform(df)
#主成分得点
pd.DataFrame(feature, columns=["PC{}".format(x + 1) for x in range(100)]).head()


"""#累積寄与率をプロット
plt.gca().get_xaxis().set_major_locator(ticker.MaxNLocator(integer=True))
plt.plot([0] + list( np.cumsum(pca.explained_variance_ratio_)), "-o")
plt.xlabel("Number of principal components")
plt.ylabel("Cumulative contribution rate")
plt.grid()
plt.show()
"""

"""# 第一主成分と第二主成分における観測変数の寄与度をプロットする
plt.figure(figsize=(6, 6))
for x, y, name in zip(pca.components_[0], pca.components_[1], range(100)):
    plt.text(x, y, name)
    #print(x,y,name)

plt.scatter(pca.components_[0], pca.components_[1], alpha=0.8)
plt.grid()
plt.xlabel("PC1")
plt.ylabel("PC2")
plt.show()
"""

"""#第一主成分と第二主成分の散布図
plt.figure(figsize=(6, 6))
plt.scatter(feature[:4999, 0], feature[:4999, 1], alpha=0.5, c='red', label='Chitoitsu')
plt.scatter(feature[5000:9999, 0], feature[5000:9999, 1], alpha=0.5, c='blue', label='Kokushimuso')
plt.scatter(feature[15000:20000, 0], feature[15000:20000, 1], alpha=0.5, c='yellow', label='tanyao')
plt.scatter(feature[10000:14999, 0], feature[10000:14999, 1], alpha=0.5, c='green', label='suanko')
plt.grid(True)
plt.xlabel("PC1")
plt.ylabel("PC2")
plt.legend(loc='upper left')
plt.show()
"""

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2