lightGBM

1138-魏同学

发表文章数:75

热门标签

首页 » 算法 » 正文

from lightgbm import LGBMRegressor
from xgboost import XGBRegressor
import numpy as np
import pandas as pd
train = pd.read_csv('./zhengqi_train.txt',sep = '/t')
test = pd.read_csv('./zhengqi_test.txt',sep = '/t')
X_train = train.iloc[:,:-1]
y_train = train['target']
X_train.shape

lightGBM

%%time
light = LGBMRegressor()
light.fit(X_train,y_train)
y_ = light.predict(test)
pd.Series(y_).to_csv('./light.txt',index = False)
%%time
xgb = XGBRegressor(max_depth = 50,n_estimators = 100)
xgb.fit(X_train,y_train)
y_ = xgb.predict(test)
pd.Series(y_).to_csv('./xgb.txt',index = False)
#协方差,两个属性之间的关系,协方差绝对值越大,两个属性之间的关系越密切
cov = train.cov()
#目标值和属性之间的关系
cov
#协方差较小,定义为不太重要的参数
drop_labels = cov.index[cov.loc['target'].abs()<0.1]#abs绝对值
drop_labels.shape
#把不重要属性去除

X_train.drop(drop_labels,axis = 1,inplace = True)
X_train.shape

lightGBM

light = LGBMRegressor()
light.fit(X_train,y_train)
y_ = light.predict(test)
pd.Series(y_).to_csv('./light2.txt',index = False)
X_test = pd.read_csv('./zhengqi_test.txt',sep = '/t')
#删除样本不均匀的特征
drop_labels = ["V5","V9","V11"]
X_train = train.iloc[:,0:-1]
X_test = pd.read_csv('./zhengqi_test.txt',sep = '/t')
X_train.drop(drop_labels,axis = 1,inplace = True)
X_test.drop(drop_labels,axis = 1,inplace = True)
X_test.shape
light = LGBMRegressor()
light.fit(X_train,y_train)
y_ = light.predict(X_test)
pd.Series(y_).to_csv('./light3.txt',index = False)
标签:

未经允许不得转载:作者:1138-魏同学, 转载或复制请以 超链接形式 并注明出处 拜师资源博客
原文地址:《lightGBM》 发布于2020-10-25

分享到:
赞(0) 打赏

评论 抢沙发

评论前必须登录!

  注册



长按图片转发给朋友

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

Vieu3.3主题
专业打造轻量级个人企业风格博客主题!专注于前端开发,全站响应式布局自适应模板。

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

Q Q 登 录
微 博 登 录