Skip to content

Instantly share code, notes, and snippets.

from sklearn.preprocessing import LabelEncoder
from sklearn.utils.validation import check_random_state, check_X_y, check_array
import numpy as np
import theano.tensor as T
import theano
class LogisticRegression(object):
floatX = theano.config.floatX
@hlin117
hlin117 / timer.py
Created February 25, 2016 07:55
Timer.py: Quick ways to time blocks of code.
from __future__ import print_function
import time
import sys
__author__ = "Henry Lin <hlin117@gmail.com>"
class Timer(object):
"""Implements a timer which clocks the amount of time it takes for
a piece of code to run. It wraps a "context", which makes timing
the code unobtrusive.
@hlin117
hlin117 / notification.py
Last active February 22, 2016 18:56
Email notification script: Emails you when your job has finished running. Read the docstring for how to use.
import smtplib
from email.mime.text import MIMEText
import time
from time import strftime
import traceback
__author__ = "Henry Lin <hlin117@gmail.com>"
__version__ = "0.1"
class Notification(object):
@hlin117
hlin117 / script.py
Last active August 29, 2015 14:25
scikit-learn bug #4942 test
from time import time
import numpy as np
from sklearn import svm
print("Starting the timer")
start = time()
xx, yy = np.meshgrid(np.linspace(-5, 5, 500), np.linspace(-5, 5, 500))
# Generate train data
X = 0.3 * np.random.randn(100000, 2)
X_train = np.r_[X + 2, X - 2]
@hlin117
hlin117 / R_output.csv
Last active January 10, 2019 13:05
MDLP discretization in python
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
"Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species"
"1" 1 3 1 1 "setosa"
"2" 1 2 1 1 "setosa"
"3" 1 2 1 1 "setosa"
"4" 1 2 1 1 "setosa"
"5" 1 3 1 1 "setosa"
"6" 1 3 1 1 "setosa"
"7" 1 3 1 1 "setosa"
"8" 1 3 1 1 "setosa"
"9" 1 1 1 1 "setosa"
" Author: Henry Lin
"
" Here are some helpful vim settings that vim may not have on by default.
" To toggle any of these settings off, simply append a " character to the
" front of the line
"
" If there's ever a setting you think this file does not have, then
" look it up! There is plenty of documentation online to help you
" customize your vim. In particular, this .vimrc does not mention
" much about key remapping, which may be of interest to some of you.
@hlin117
hlin117 / Compiler output
Created January 13, 2015 03:31
compiler output after running make on current *.tar.br2 file on vim site
CC="gcc -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -no-cpp-precomp " srcdir=. sh ./osdef.sh
gcc -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -no-cpp-precomp -O6 -o objects/buffer.o buffer.c
warning: optimization level '-O6' is unsupported; using '-O3' instead
1 warning generated.
gcc -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -no-cpp-precomp -O6 -o objects/blowfish.o blowfish.c
warning: optimization level '-O6' is unsupported; using '-O3' instead
1 warning generated.
gcc -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -no-cpp-precomp -O6 -o objects/charset.o charset.c
warning: optimization level '-O6' is unsupported; using '-O3' instead
1 warning generated.
@hlin117
hlin117 / wma_convert.py
Last active August 29, 2015 14:03
A quick gist to convert wma files in a folder to mp3 files. Uses the command line tool ffmpeg.
#!/usr/bin/python
import os
for file in os.listdir("."):
if file.endswith("wma"):
name = file[:-4]
command = "ffmpeg -i '{0}.wma' '{0}.mp3' -y".format(name)
os.system(command)