본문 바로가기
R-기타

lightgbm binaryclass/multiclass/regression

by 미스터탁 2018. 10. 4.



#저장용



######binary

model_list<-list()

for(i in 1:10){

  ss<-sample(1:length(nlab),length(nlab)*1,replace = T)

  

  library(lightgbm)

  params <- list( objective = "binary", metric = "AUC",nrounds=800, depth=4, leaves=30,  col_sample=0.8,

                  row_sample=0.8, learn_rate=0.015)

  table(lab[sam])

  

  dtrain <- lgb.Dataset(rbind(tr3[ss,]),label=nlab[ss])

  dvalid <- lgb.Dataset(rbind(tr3[-ss,]),label=nlab[-ss])

  

  

  valids <- list(test = dvalid)

  

  model2 <- lgb.train(params,

                      dtrain,100,valids,

                      eval_freq = 10,

                      # device="gpu",

                      # gpu_platform_id = 1,

                      # gpu_device_id = 0,

                      learning_rate = 0.002,

                      early_stopping_rounds =100)

  

  model_list[[i]]<-model2

  

  cat("\n",i)

}



#########multiclass


    dtrain <- lgb.Dataset(data = train[as.numeric(ti2),],label =(train_y)[as.numeric(ti2)])

  dvalid <- lgb.Dataset(data = train[as.numeric(ti),],label =train_y[as.numeric(ti)])

  

  valids <- list(test = dvalid)

  params <- list(objective="multiclass", metric="multi_error",num_class =9)

  model <- lgb.train(params, dtrain, 100, valids, min_data = 5,depth=16, leaves=300,  col_sample=0.8,

                     row_sample=0.8, learning_rate = 0.15, early_stopping_rounds = 10,eval_freq = 50) 

  

  

  

  vy<-model$predict(((train[as.numeric(ti),])))

  vy2<-matrix(vy,ncol=ul,byrow=T)

  pred<-apply(vy2,1,which.max)

  rs<-sum((pred-1)==(train_y)[as.numeric(ti)])/length(pred);rs



#############regression


 library(lightgbm)

dtrain <- lgb.Dataset(data = as.matrix(data[sam,-ncol(data)]), label = data$y[sam]) 

dvalid <- lgb.Dataset(data =as.matrix(data[-sam,-ncol(data)]), label = data$y[-sam]) 

valids <- list(test = dvalid)

params <- list(objective = "regression_l2", metric = "l2" ) 

model <- lgb.train(params, dtrain, 500, valids, min_data = 5,depth=16, leaves=300,  col_sample=0.3,eval_freq = 20,

                   row_sample=0.5, learning_rate = 0.1, early_stopping_rounds = 10) 

# model <- lgb.cv(params, dtrain, 500, nfold = 5, min_data = 5,depth=4, leaves=10,  col_sample=0.3,eval_freq = 20,

#                    row_sample=0.5, learning_rate = 0.15, early_stopping_rounds = 10)

pr<-predict(model,as.matrix(data[-sam,-ncol(data)]))*1






인프런 강의 할인 쿠폰 코드입니다.


R로 하는 웹 크롤링 - 입문편(할인쿠폰코드) 236-69fc51d93a53 

https://www.inflearn.com/course/R-crawling# 


R로 하는 웹 크롤링 - 실전편 (할인쿠폰코드) 237-55c672aeb038 

https://www.inflearn.com/course/R-crawling-2# 


R로 하는 텍스트마이닝 (Top keyword부터 감성분석까지) (할인쿠폰코드) 238-c86096730061 

https://www.inflearn.com/course/R-text-mining#



R로 무작정 해보는 data science (할인쿠폰코드) 310-c6164f3d9be9 

https://www.inflearn.com/course/R-%EB%8D%B0%EC%9D%B4%ED%84%B0%EC%82%AC%EC%9D%B4%EC%96%B8%EC%8A%A4-%EB%9D%BC%EC%9D%B4%EB%B8%8C%EC%BD%94%EB%94%A9#


반응형

'R-기타' 카테고리의 다른 글

R에서 Keras 설치하기  (0) 2018.05.01
Matrix에서 행별로 다른 칼럼에 있는 data가져오기  (0) 2018.04.27
LightGBM 설치하기  (5) 2018.04.22
Matlab imgae 파일 R로 불러들이기  (0) 2018.04.12
R기초 코드  (0) 2018.04.04

댓글