Skip to content

Instantly share code, notes, and snippets.

View Torenable's full-sized avatar

Richard Huang Torenable

View GitHub Profile
@Torenable
Torenable / xgb_tb.py
Last active January 3, 2021 03:33 — forked from tsu-nera/xgb_tb.py
xgboost visualization with tensorboard
'''
Updates:
1. Using tensorboardX to replace tensorboard_logger as I prefer tensorboardX's API
2. Log the tree growth process, which would be displayed under "IMAGES" tab in Tensorboard
'''
import pandas as pd
import xgboost as xgb
from sklearn.model_selection import train_test_split
-- When encoutner "SQL Error [42704]: ERROR: type "geography" does not exist", try the following
CREATE EXTENSION Postgis;
@Torenable
Torenable / knime Batch execute
Last active March 11, 2021 19:23 — forked from semeltheone/knime Batch execute
Knime Execute Workflows from the Commandline
# Windows:
knime.exe -consoleLog -noexit -nosplash -application org.knime.product.KNIME_BATCH_APPLICATION -workflowFile="PathToYourWorkflow.zip" -destFile="OutputPathToYourWorkflow.zip"
# Mac
/Applications/KNIME\ 3.5.3.app/Contents/MacOS/Knime -nosplash -application org.knime.product.KNIME_BATCH_APPLICATION -workflowFile="PathToYourWorkflow.zip" -destFile="OutputPathToYourWorkflow.zip"
# Linux
knime -nosplash -application org.knime.product.KNIME_BATCH_APPLICATION -workflowFile="PathToYourWorkflow.zip" -destFile="OutputPathToYourWorkflow.zip"
@Torenable
Torenable / authorization_flask.py
Created February 11, 2018 20:29
Auth decorator for Flask
# http://book.pythontips.com/en/latest/decorators.html
from functools import wraps
from flask import request
def requires_auth(func):
@wraps(func)
def wrapper(*args, **kwargs):
auth = request.authorization
if not auto or not check_auth(auth.username, auth.password):
@Torenable
Torenable / use_list_as_parameter.R
Last active July 13, 2017 00:44
Example of using a list as named parameters. Then can use JSON to pass parameters.
paras = jsonlite::read_json("/path/to/config.json")
do.call("func", paras) # analogue using dictionary as keywoard paramters `func(**paras)` in python
do.call(func, paras)
library(ggplot2)
# var ~ grp
ggplot(aes(x = grp, y = var)) + geom_boxplot()
@Torenable
Torenable / rJava_loader.R
Created July 1, 2017 18:41
Loading dynamic library for Java in R
# Credit to Paul Klemm's post [Load rJava in RStudio using macOS 10.12](http://paulklemm.com/blog/2017-02-12-fix-onload-failed-rjava-macos/)
dyn.load(paste0(system2('/usr/libexec/java_home', stdout = TRUE), '/jre/lib/server/libjvm.dylib'))
# then load any packages associated to JVM
@Torenable
Torenable / EM_decomposition.r
Last active June 15, 2017 14:35
Decomposite a Gaussian mixed univariate in R
library(mixtools)
mixmdl = normalmixEM(train$y)
plot(mixmdl, which = 2)
lines(density(train$y), lty=2, lwd=2)
# credit to [Ron Pearson](https://www.r-bloggers.com/fitting-mixture-distributions-with-the-r-package-mixtools/)
@Torenable
Torenable / sklearn_template.py
Last active July 17, 2017 04:01
sklearn skeleton
import sklearn
######################
# Estimator
######################
# (Analogue to Keras) Initialization all-in-one
# bind symbol
# define loss function + optimizer
# (optional) metrics for output evaluation
@Torenable
Torenable / monetdb_bulk_load_csv.sql
Last active May 25, 2017 22:39
Bulk load a CSV (with header) to the target table from Mac
COPY OFFSET 2 INTO target.table FROM '/full/path/to/the.csv'
USING
DELIMITERS ',', '\n', '\"'
NULL AS ''