科学の箱

科学・IT・登山の話題

Python

kaggle Titanic Tutorial – 2

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

決定木を利用して分析する。

データの作成


y_train = d_train["Survived"].values
x_train = d_train[["Pclass", "Sex", "Age", "Fare", "Parch", "Embarked", "SibSp"]].values
x_test = d_test[["Pclass", "Sex", "Age", "Fare", "Parch", "Embarked", "SibSp"]].values

予測モデル作成


from sklearn.tree import DecisionTreeClassifier
dtree = DecisionTreeClassifier()
dtree.fit(x_train,y_train)

predictions = dtree.predict(x_test)

提出ファイル作成


kaggle_submission = pd.DataFrame({
"PassengerId": d_test["PassengerId"],
"Survived": predictions
})

kaggle_submission.to_csv("kaggle_submission.csv", index=False)

メタ情報

inarticle



メタ情報

inarticle



-Python
-,

執筆者:


comment

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

関連記事

no image

automated the boring – day 3

https://automatetheboringstuff.com/ 今回はまずは文字列操作から。とりあえず基本のところを押さえておく。 print("Hello there!\nHow …

no image

pyperclipを設定する

pyperclipはpip3経由でインストールする。まずはpip3のインストールから。 https://bootstrap.pypa.io/get-pip.pyからget-pip.pyをダウンロードし …

no image

cp932 error

pythonで入力ファイルにおける文字コードが正しく認識されない場合、以下のようなエラーがでる。 UnicodeDecodeError: ‘cp932’ codec can&# …

no image

数字、計算、文字列を画面出力

Hello Worldができたので、いろいろな出力を試してみる。 出力はprint関数を使えばよい。 まずは数値から試してみる。数値は文字列と違い引用符で囲む必要はない。画面に直接表示するので変数は使 …

no image

condaでjupyter notebookが使えないとき

condaで環境を作るとjupyter notebookはインストールされていない。 この場合には個別にjupyterをインストールすればよい。   conda install jupyte …

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

side bar top



アーカイブ

カテゴリー