Skip to content

Instantly share code, notes, and snippets.

@ymtky
ymtky / gist:d64281fd123d11b9e52ca7c3ae9b526f
Last active September 11, 2019 11:53
xgboost + optuna
import optuna
from functools import partial
import xgboost as xgb
from sklearn.metrics import f1_score
def objective(dtrain, dtest, trial):
max_depth = trial.suggest_int('max_depth',1,10)
eta = trial.suggest_uniform('eta',0.0,1)
subsample = trial.suggest_uniform('subsample', 0.5, 1)
colsample_bytree = trial.suggest_uniform('colsample_bytree', 0.5, 1)
@ymtky
ymtky / border.swift
Created September 17, 2018 10:03
[Swift] UIViewの1辺にボーダーを設定
let bottomBorder = CALayer()
bottomBorder.frame = CGRect(x: 0, y: view.frame.height - 1, width: view.frame.width, height: 1.0)
bottomBorder.backgroundColor = UIColor.lightGray.cgColor
view.layer.addSublayer(bottomBorder)
@ymtky
ymtky / ReosurcesGetter.java
Last active January 16, 2018 05:38
Javaでresources化のファイルを取得する
public final class ReosurcesGetter {
public List<File> get(String path, String extension) {
File rootFile = new File(getClass().getResource(path).getPath());
return getRecursiveFiles(rootFile, extension);
}
// ファイルを再帰的に取得
private List<File> getRecursiveFiles(File file, String extension) {
Optional<File[]> maybeFiles = Optional.ofNullable(file.listFiles());
List<File> result = new ArrayList<>();
@ymtky
ymtky / gist:1a39a6f61c8d830f6c46a8402618f3c1
Created January 11, 2018 05:34
json schemaで外のファイルを参照する場合の指定
// httpで
"$ref": "http://schema/hogehoge.json"
// 絶対パス
"$ref": "file:///schema/hogehoge.json"
// mavenプロジェクトのresources下の相対パス
"$ref": "resource:/schema/hogehoge.json"
タイポを置換で直す
git grep -l 'hogehoge' | xargs sed -i '' -e 's/hogehoge/hugahuga/g'
コミットのauthor dateを現在時刻にする
git commit --amend --date "`date`"
@ymtky
ymtky / gist:24fdc4bac3c918783fd8f4b0c1b9a5d7
Last active November 6, 2017 07:16
vim置換正規表現メモ
\数値で正規表現にマッチした文字列を参照する
:%s/hogehoge: \(\"[^\"]*\"\)/hugahuga: \1
改行を挿入する時は\r
:%s/\(hogehoge: \"[^\"]*\"\)/\1\r
@ymtky
ymtky / bot.js
Last active September 16, 2017 08:40
株価bot
const fetch = require('node-fetch');
module.exports = ( robot => {
robot.respond(/(.*)\s(.*)/, msg => {
Promise.all([fetchCurrentStockData(msg.match[2]), fetchDailyStockData(msg.match[2])]).then(values => {
const current = values[0]
//日次データから最新の前日のデータを取り出す
const dailyLatest = values[1][values[1].length - 1]
const dailyOneBefore = values[1][values[1].length - 2]
const yesterday = dailyLatest['DATE'].getMonth() == current['DATE'].getMonth()
@ymtky
ymtky / pandas
Created June 9, 2017 03:23
pandasメモ
#DataFrameから2次元配列
dataframe.values.toList()
#列名で選択
dataframe.loc[:,['A','B']]
//モックを宣言
@Mocked
Hoge hoge;
//フィールドへの差込み
Deencapsulation.setField(hoge, "field" ,"hugahuga");
//メソッドへの差込み
when(hoge.get()).thenReturn("hugahuga"));
@ymtky
ymtky / google_finance.py
Last active September 8, 2018 13:53
google financeのAPI使用サンプル
import requests
from datetime import datetime, timedelta
import pandas as pd
url = "https://www.google.com/finance/getprices"
code = 7203
lsat_date = datetime.now() #データの取得開始日
interval = 86400 #データの間隔(秒)。1日 = 86400秒
market = "TYO" #取引所のコード TYO=東京証券取引所
period = "1Y" #データを取得する期間