アットウィキロゴ

艦これ初期ステータスで艦種アキネーターを作る手順

No. Activity 備考
1

まとめWikiで元になるデータを取得する。
図鑑No順の表についてExcelに転記する。

https://t.co/SqXHM6c93s
 

これぐらいの分量の表の前処理ならExcelのほうが楽。

「1」のExcelで今回使わないデータを削除する。
・列名が繰り返し挿入されているので、その行を削除。
・改、時報、備考を削除。
・ステータスが空白の行を削除。No.198など。
改はカンマで区切ってあるので、
どうしてもこの列をCSVに変換するときは注意。
3 「2」のExcelデータの表をCSVに変換。 kankore.csv
4 Python 3、日本語フォントの入ったLinuxで、
以下のimportが行える環境を作成。
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn import preprocessing
import sklearn.model_selection
import sklearn.ensemble
from sklearn import tree
import pydotplus as pdp
graphvizはyumでインストール。(CentOSの場合)
5

「3」で作ったCSVを「4」の環境にコピー。

以後、homeディレクトリにCSVを置いているとします。
6
import pandas as pd
from sklearn.model_selection import train_test_split
 
df = pd.read_csv('~/kankore.csv')
target = df['艦種']
features = df.drop(['No.','艦型', '艦番','艦種','艦名'],axis=1)
 
from sklearn import preprocessing
le = preprocessing.LabelEncoder()
for col in ['速力', '射程']:
   features[col] = le.fit_transform(features[col])
 
target = le.fit_transform(target)
import sklearn.model_selection
train_x, test_x, train_y, test_y = sklearn.model_selection.train_test_split(features, target, test_size=0.3)
 
 
import sklearn.ensemble
rf = sklearn.ensemble.RandomForestClassifier()
rf.fit(train_x, train_y)
 
prediction = rf.predict(test_x)
print(prediction)
accuracy = rf.score(test_x, test_y)
print('accuracy {0:.2%}'.format(accuracy))
 
estimators = rf.estimators_
file_name = "./tree_visualization.png"
from sklearn import tree
 
 
 
dot_data = tree.export_graphviz(estimators[0],
  out_file=None,
  filled=True, 
  rounded=True, 
  feature_names=features.columns,
  class_names=df['艦種'],
  special_characters=True
)
 
import pydotplus as pdp
graph = pdp.graph_from_dot_data(dot_data)
graph.write_png(file_name)
最初のうちは、インタプリタ(一行ずつ実行)をさせておいたほうが
問題が起きたときに対処しやすいです。
参考
https://t.co/X1XdNkiXVg
 
7 homeディレクトリに作成された「tree_visualization.png」を確認。
この図が艦種特定の質問文になっています。
 

 

最終更新:2018年02月17日 16:57