Skip to content

Instantly share code, notes, and snippets.

View smly's full-sized avatar
👁️‍🗨️

smly smly

👁️‍🗨️
View GitHub Profile
def objective(trial):
data, target = sklearn.datasets.load_breast_cancer(return_X_y=True)
train_x, test_x, train_y, test_y = train_test_split(data, target, test_size=0.25)
dtrain = lgb.Dataset(train_x, label=train_y)
param = {
'objective': 'binary',
'metric': 'binary_logloss',
'lambda_l1': trial.suggest_loguniform('lambda_l1', 1e-8, 10.0),
'lambda_l2': trial.suggest_loguniform('lambda_l2', 1e-8, 10.0),
import sklearn.datasets
import sklearn.metrics
import xgboost as xgb
import optuna
# FYI: Objective functions can take additional arguments
# (https://optuna.readthedocs.io/en/stable/faq.html#objective-func-additional-args).
def objective(trial):
@smly
smly / lightgbm_integratio.patch
Last active July 9, 2023 08:20
Usage of custom eval metric function with Optuna
diff --git a/examples/pruning/lightgbm_integration.py b/examples/pruning/lightgbm_integration.py
index 8e623772..4c0c315c 100644
--- a/examples/pruning/lightgbm_integration.py
+++ b/examples/pruning/lightgbm_integration.py
@@ -21,6 +21,15 @@ import optuna
# FYI: Objective functions can take additional arguments
# (https://optuna.readthedocs.io/en/stable/faq.html#objective-func-additional-args).
def objective(trial):
+ def custom_accuracy_pct(preds, data):
+ y_true = data.get_label()
import pandas as pd
import lightgbm as lgb
# データをロード
df_train = pd.read_csv('./train.csv')
df_test = pd.read_csv('./test.csv')
# データフレームを「訓練」「テスト」の順番に連結する
df = pd.concat([df_train, df_test], sort=False)
"""
Public LB: 0.50456
"""
from collections import Counter
import lightgbm as lgb
import ml_metrics
import numpy as np
import pandas as pd
from sklearn.feature_extraction import DictVectorizer
@smly
smly / example_donorschoose.py
Created September 5, 2019 13:51
OptunaLGBM
# Python script using data from DonorsChoose.org Application Screening
# Forked from https://www.kaggle.com/opanichev/lightgbm-and-tf-idf-starter
# Original version: Validation score: 0.7791025740062782
# - Private Score 0.78470
# - Public Score 0.79516
# Tuned version: Validation score: 0.7799395759019241
# - Private Score 0.78622
# - Public Score 0.79535
@smly
smly / 190110_limit_on_file_name_length_in_linux.patch
Last active January 9, 2019 20:33
w3m patch (origin: shinh/w3m)
diff --git a/file.c b/file.c
index 6069770..76bb5e6 100644
--- a/file.c
+++ b/file.c
@@ -8526,12 +8526,14 @@ guess_save_name(Buffer *buf, char *path)
if ((p = checkHeader(buf, "Content-Disposition:")) != NULL &&
(q = strcasestr(p, "filename")) != NULL &&
(q == p || IS_SPACE(*(q - 1)) || *(q - 1) == ';') &&
- matchattr(q, "filename", 8, &name))
- path = name->ptr;
@smly
smly / switchbot.py
Last active August 8, 2021 09:52
CLI for swithbot
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Usage: switchbot [OPTIONS]
Options:
-d, --device [light|speaker.tv|speaker.mpd|aircon]
[required]
--on
--off

Keybase proof

I hereby claim:

  • I am smly on github.
  • I am smly (https://keybase.io/smly) on keybase.
  • I have a public key ASCQq0Kd4zZ_oWh3AhmyznhCAKx1FsnvZNx5n2pKyl5ejgo

To claim this, I am signing this object:

@smly
smly / audiolab_convert.py
Last active September 25, 2016 06:24
neon.data.dataloader.DataLoader, runtime_error of "Could not decode media stream"
# -*- coding: utf-8 -*-
"""
Original code: prep.py on https://github.com/anlthms/sp-2016.git
* invalid media stream: 2_1418_0.3.wav
* valid media stream: 2_1418_0.2.wav
md5 checksum
-------------
964a651d454ff8a2b77ccd35e20d0805 /opt/nih_seizure/train_2.zip