科学の箱

科学・IT・登山の話題

Python 機械学習

kaggle Titanic Tutorial – 3

投稿日:2018年5月24日 更新日:

DecitionTreeのパラメータを調整する。

まずはMaxDepthから


from sklearn.model_selection import LeaveOneOut
from sklearn.metrics import accuracy_score
MAX_DEPTH = 20
depths = range(1, MAX_DEPTH)

loo_Y = d_train["Survived"].values
loo_X = d_train[["Pclass", "Sex", "Age", "Fare", "Parch", "Embarked", "SibSp"]].values

accuracy_scores = []
for depth in depths:

predicted_labels = []
loo = LeaveOneOut()
for train_index, test_index in loo.split(loo_X):
X_train, X_test = loo_X[train_index], loo_X[test_index]
y_train, y_test = loo_y[train_index], loo_y[test_index]
clf = DecisionTreeClassifier(max_depth=depth)
clf.fit(X_train, y_train)

predicted_label = clf.predict(loo_X[test_index])
predicted_labels.append(predicted_label)

score = accuracy_score(loo_Y, predicted_labels)
print('max depth={0}: {1}'.format(depth, score))

max depth=1: 0.7867564534231201
max depth=2: 0.6936026936026936
max depth=3: 0.8181818181818182
max depth=4: 0.8237934904601572
max depth=5: 0.8181818181818182
max depth=6: 0.8103254769921436
max depth=7: 0.8215488215488216
max depth=8: 0.8249158249158249
max depth=9: 0.8204264870931538
max depth=10: 0.8148148148148148
max depth=11: 0.8058361391694725
max depth=12: 0.8002244668911336
max depth=13: 0.797979797979798
max depth=14: 0.7934904601571269
max depth=15: 0.7912457912457912
max depth=16: 0.7755331088664422
max depth=17: 0.77665544332211
max depth=18: 0.7833894500561167
max depth=19: 0.7744107744107744

MaxDepthは8を利用する。

メタ情報

inarticle



メタ情報

inarticle



-Python, 機械学習
-,

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

ウェブ分析をハンズオンで学ぶ

ウェブ分析の本を読んでもあまりあたまに入ってこない。実際に手を動かさないと、身につかないわけである。 ということでハンズオンで実践して見ることにした。ハンズオンで実践するに当たり必要なのはデータとツー …

no image

実践ワークショップExcel徹底活用ビジネスデータ分析

メモ 相関係数の行列で傾向が似ている変数を探すことができる。例えば過去データとして商品A,B,C,D,E,Fがあるとする。今商品Xを開発し、マーケティング方法を決めたい。この時A~Fについてはすでに売 …

no image

単回帰でデータフレームの形式を整える

values.reshape(-1, 1)が必要。 Related posts:automated the boringNumPyを使ってみるNumpyまとめ

no image

仕事で始める機械学習 – 2.機械学習で何ができるか – 分類 – ロジスティック回帰

ロジスティック回帰 確率を得るために パーセプトロンの判別式により確率をとることはできない。パーセプトロンのヒンジ損失は正負のみを判断し、間違っている場合だけパラメータの更新をする。つまりぎりぎりで正 …

no image

線形解析の基本手順

線形解析の基本手順 データの読み込み データフォーマット確認 EDA データクレンジング トレーニングデータ構築 モデル構築 モデル評価 予想 メトリック Related posts:dataanal …

2018年5月
« 4月   6月 »
 123456
78910111213
14151617181920
21222324252627
28293031  

side bar top



アーカイブ

カテゴリー