Skip to content

Instantly share code, notes, and snippets.

@rspeare
rspeare / parallel_pandas_apply.py
Last active December 19, 2019 19:28
Cute Parallel Pandas Apply example
from joblib import Parallel, delayed
import functools
import pandas as pd
def parallel_apply(partition_col=None, n_partitions=None):
"""
This decorator wraps any transformer function that takes in a pandas dataframe as some keyword argument, "data",
and returns a pandas dataframe.
Signature must be:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rspeare
rspeare / p_values_for_logreg
Created October 16, 2017 01:27
P values for sklearn logistic regression
# test
@rspeare
rspeare / logistic_reg.py
Last active April 3, 2021 00:18
Sklearn Logistic Regression wrapper for Active Learning and p-value estimation
from sklearn.linear_model import LogisticRegression
import numpy as np
import scipy.stats as stat
from scipy.sparse import issparse
class ActiveLearningLogisticRegression(LogisticRegression):
""" Wrapper class for scikit-learn's Logistic Regression classifier.
New Attributes:
---------------
@rspeare
rspeare / p_values_for_logreg.py
Last active February 4, 2024 02:50
P values for sklearn logistic regression
from sklearn import linear_model
import numpy as np
import scipy.stats as stat
class LogisticReg:
"""
Wrapper Class for Logistic Regression which has the usual sklearn instance
in an attribute self.model, and pvalues, z scores and estimated
errors for each coefficient in