科学の箱

科学・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

kaggle Titanic Tutorial – 10

いろいろ試しているがうまくいかないので、とりあえずAgeを正しく補完できるか調べる。 調査は線形回帰でどれくらい相関が出るかで判断する。   import numpy as nm impor …

no image

Python + Slack Bot – 3

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

no image

Scrapy – Install

インストールガイドはこちら https://doc.scrapy.org/en/latest/intro/install.html#intro-install anacondaにインストールする co …

no image

flip, fliplr, flipudを使って配列要素を上下左右、左右、上下反転する

画像処理などでは要素の値を配列全体で反転したいときがある。このようなときに役に立つのがflip, fliplr, flipudである。 flipのマニュアル fliprのマニュアル flipudのマニ …

no image

automated the boring

まずは肩慣らし print(‘Hello world!’) print(‘What is your name?’) # ask for their na …

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

side bar top



アーカイブ

カテゴリー