Skip to content

Instantly share code, notes, and snippets.

@aswalin
Last active September 5, 2019 07:37
Show Gist options
  • Save aswalin/effa427b3e4cc047c1118cad8977fed5 to your computer and use it in GitHub Desktop.
Save aswalin/effa427b3e4cc047c1118cad8977fed5 to your computer and use it in GitHub Desktop.
import lightgbm as lgb
from sklearn import metrics
def auc2(m, train, test):
return (metrics.roc_auc_score(y_train,m.predict(train)),
metrics.roc_auc_score(y_test,m.predict(test)))
lg = lgb.LGBMClassifier(silent=False)
param_dist = {"max_depth": [25,50, 75],
"learning_rate" : [0.01,0.05,0.1],
"num_leaves": [300,900,1200],
"n_estimators": [200]
}
grid_search = GridSearchCV(lg, n_jobs=-1, param_grid=param_dist, cv = 3, scoring="roc_auc", verbose=5)
grid_search.fit(train,y_train)
grid_search.best_estimator_
d_train = lgb.Dataset(train, label=y_train)
params = {"max_depth": 50, "learning_rate" : 0.1, "num_leaves": 900, "n_estimators": 300}
# Without Categorical Features
model2 = lgb.train(params, d_train)
auc2(model2, train, test)
#With Catgeorical Features
cate_features_name = ["MONTH","DAY","DAY_OF_WEEK","AIRLINE","DESTINATION_AIRPORT",
"ORIGIN_AIRPORT"]
model2 = lgb.train(params, d_train, categorical_feature = cate_features_name)
auc2(model2, train, test)
@magusafr
Copy link

You need add 'free_raw_data=False' in lgb.Dataset
d_train = lgb.Dataset(train, label=y_train, free_raw_data=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment