科学の箱

科学・IT・登山の話題

Python

kaggle Titanic Tutorial – 11

投稿日:2018年6月12日 更新日:

kaggleで人気があるlightGBMをつかってみる。

 

インストール


pip install lightgbm

特に問題がなく終了。

コード、関係するところだけ記載。


split_before_y = d_train["Survived"].values
split_before_x = d_train.drop("Survived",axis=1)

X_train,X_test,y_train,y_test = train_test_split(split_before_x,split_before_y,test_size=0.008,random_state=0)

import lightgbm as lgb

lgb_train = lgb.Dataset(X_train, y_train)
lgb_eval = lgb.Dataset(X_test, y_test, reference=lgb_train)

params = {
'task': 'train',
'boosting_type': 'gbdt',
'objective': 'regression',
'metric': {'l2'},
'num_leaves': 200,
'learning_rate': 0.003,
'feature_fraction': 0.50,
'bagging_fraction': 0.80,
'bagging_freq': 7,
'verbose': 0
}
gbm = lgb.train(params, lgb_train, num_boost_round=1000, valid_sets=lgb_eval, early_stopping_rounds=200)

Y_pred = gbm.predict(d_test.drop("PassengerId",axis=1).copy(), num_iteration=gbm.best_iteration)

for i in range(418):
if Y_pred[i]>=0.51:
Y_pred[i]=
else:
Y_pred[i]=0

kaggle_submission = pd.DataFrame({
"PassengerId": d_test["PassengerId"],
"Survived": Y_pred.astype('int64')
})

 

結果は大幅な改善。0.80861となった。

メタ情報

inarticle



メタ情報

inarticle



-Python
-,

執筆者:


comment

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

関連記事

no image

Python + Slack Bot – 3

さてリアルタイムでとりあえずうまくいったので、もう少し違うサンプルコードを試してみる。 参考にしたのはこちら。 https://www.fullstackpython.com/blog/build-f …

no image

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

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

no image

flickrapiを使うための手順

https://stuvel.eu/flickrapiで提供されるflickrapiを利用するにあたり、エラーが出てインストールできない。 condaでは提供されていない pipはSSLError(S …

no image

Pillowのインストールは成功しているのにエラーが出る

from . import _imaging as core ImportError: DLL load failed: The specified module could not be found …

no image

django install

まずはdjangoをインストールする pip install django   Versionを確認する python -m django –version はじめてのプロジェク …

2018年6月
« 5月   9月 »
 123
45678910
11121314151617
18192021222324
252627282930  

side bar top



アーカイブ

カテゴリー