Skip to content

Instantly share code, notes, and snippets.

Adam Levin adamwlev

Block or report user

Report or block adamwlev

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@adamwlev
adamwlev / NaturalSpline.py
Created May 3, 2018
Natural Spline Implementation in python
View NaturalSpline.py
## Define a class for a Natural Spline
## https://web.stanford.edu/~hastie/Papers/ESLII.pdf#page=163
class NaturalSpline():
def __init__(self,n_folds=6):
self.n_folds = n_folds
def get_mat(self,x,df):
notches = np.percentile(x,np.linspace(0,100,df+2)[1:-1])
X = np.column_stack(([1.0]*len(x),x))
def d(x,e_k,e_K):
@adamwlev
adamwlev / affine_transformation.py
Last active May 16, 2017
Affine Transformation
View affine_transformation.py
import numpy as np
def produce_transformation(tuples,tuples_t):
"""
Given points in some 2d space, and points in a transformed
2d space, produces function to tranform one space to other.
tuples : points in original space (list of x,y tuples)
tuples_t : corresponding points in transformed space (")
"""
View .block
license: gpl-3.0
@adamwlev
adamwlev / monitor.py
Last active Apr 25, 2017
Make a Monitor Function to Train a Gradient Booster from Sklearn with automated early stopping
View monitor.py
## Makes a monitor where the mean of last x oob improvements
## are used to determine early stopping. This can be ammended
## to any stopping criteria one sees as fit - consecutive x
## negatives, more negatives than positives in last x, etc.
def make_monitor(running_mean_len):
def monitor(i,self,args):
if np.mean(self.oob_improvement_[max(0,i-running_mean_len+1):i+1])<0:
return True
else:
@adamwlev
adamwlev / TheRightAndWrongWaytoDoCrossValidation.ipynb
Last active Sep 22, 2016
Adapted from *Elements of Statistical Learning* Friedman, Tibshirani, and Hastie
View TheRightAndWrongWaytoDoCrossValidation.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
You can’t perform that action at this time.