Skip to content

Instantly share code, notes, and snippets.

@cheevahagadog
cheevahagadog / extract_feature_effect_per_prediction.py
Last active November 17, 2020 05:36
Builds off the SHAP package to list out the feature effects per row on an XGBoost model.
#!/usr/bin/env python
# Python 3.6.4
import numpy as np
import pandas as pd
import iml
import xgboost
import shap
from tqdm import tqdm
@MMesch
MMesch / minimal_cwt.py
Last active September 11, 2018 13:26
Minimal Continuous Wavelet Transform
#!/usr/bin/env python
"""Mini implementation of continuous wavelet transform (Morlet wavelet)."""
import numpy as np
import matplotlib.pyplot as plt
def continuous_wavelet_transform(signal, frequencies, time_step=1.0,
wavelet_width=5):
from urllib.parse import urlparse
import lightgbm as lgb
import threading
def _parse_machines(workers, listen_port):
"""From dask worker info to LightGBM mlist"""
# TODO: Assert that we're using TCP?
mlist = ['127.0.0.1:{}'.format(listen_port)] + [urlparse(worker).netloc
for worker in workers]
@kevinzakka
kevinzakka / data_loader.py
Last active April 19, 2024 23:42
Train, Validation and Test Split for torchvision Datasets
"""
Create train, valid, test iterators for CIFAR-10 [1].
Easily extended to MNIST, CIFAR-100 and Imagenet.
[1]: https://discuss.pytorch.org/t/feedback-on-pytorch-for-kaggle-competitions/2252/4
"""
import torch
import numpy as np
@MMesch
MMesch / bspline_basis_scipy.py
Created July 21, 2017 12:51
simple script that extracts an ND Bspline basis from scipy (plots in 1D and 2D)
#!/usr/bin/env python
"""
ND Bspline basis class for Python
"""
import numpy as np
import scipy.interpolate as si
import matplotlib.pyplot as plt
import itertools
@MMesch
MMesch / robust_splines_sklearn.py
Last active July 6, 2023 23:04
Robust Spline Regression with Scikit-Learn
#!/usr/bin/env python
"""
Robust B-Spline regression with scikit-learn
"""
import matplotlib.pyplot as plt
import numpy as np
import scipy.interpolate as si
from sklearn.base import TransformerMixin
from sklearn.pipeline import make_pipeline
@MMesch
MMesch / robust_fourier_sklearn.py
Created May 22, 2017 16:27
Robust Fourier Transform and Custom Features with Scikit Learn
#!/usr/bin/env python
"""
Robust non-linear feature estimation with scikit-learn applied to
the Fourier Transform.
"""
from matplotlib import pyplot as plt
import numpy as np
from sklearn.base import TransformerMixin
from sklearn.pipeline import make_pipeline
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Nikolay-Lysenko
Nikolay-Lysenko / xgb_quantile_loss.py
Last active October 25, 2023 13:26
Customized loss function for quantile regression with XGBoost
import numpy as np
def xgb_quantile_eval(preds, dmatrix, quantile=0.2):
"""
Customized evaluational metric that equals
to quantile regression loss (also known as
pinball loss).
Quantile regression is regression that
@whophil
whophil / jupyter.service
Last active October 30, 2023 16:33 — forked from doowon/jupyter_systemd
A systemd script for running a Jupyter notebook server.
# After Ubuntu 16.04, Systemd becomes the default.
# It is simpler than https://gist.github.com/Doowon/38910829898a6624ce4ed554f082c4dd
[Unit]
Description=Jupyter Notebook
[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/home/phil/Enthought/Canopy_64bit/User/bin/jupyter-notebook --config=/home/phil/.jupyter/jupyter_notebook_config.py