Skip to content

Instantly share code, notes, and snippets.

View jtrive84's full-sized avatar

James Triveri jtrive84

View GitHub Profile
@MaxBareiss
MaxBareiss / frechet.py
Last active July 7, 2023 13:36
Fréchet Distance in Python
# Euclidean distance.
def euc_dist(pt1,pt2):
return math.sqrt((pt2[0]-pt1[0])*(pt2[0]-pt1[0])+(pt2[1]-pt1[1])*(pt2[1]-pt1[1]))
def _c(ca,i,j,P,Q):
if ca[i,j] > -1:
return ca[i,j]
elif i == 0 and j == 0:
ca[i,j] = euc_dist(P[0],Q[0])
elif i > 0 and j == 0:
@aparrish
aparrish / understanding-word-vectors.ipynb
Last active July 9, 2024 15:59
Understanding word vectors: A tutorial for "Reading and Writing Electronic Text," a class I teach at ITP. (Python 2.7) Code examples released under CC0 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
admit gre gpa rank
0 380 3.61 3
1 660 3.67 3
1 800 4 1
1 640 3.19 4
0 520 2.93 4
1 760 3 2
1 560 2.98 1
0 400 3.08 2
1 540 3.39 3
@jtrive84
jtrive84 / modelcomp.py
Created January 28, 2020 20:49
Model frequency exhibit generator
def modelcomp(df, outpath, titlestr=None):
"""
Generate partial residual model comparison exhibits.
"""
try:
pdf = PdfPages(outpath)
df = df.rename({"INCIDENCE_MNTH":"actual_count"}, axis=1)
keepfields = [i for i in df.columns if i.endswith("count")] + ["EXPOSURE"]
varcols = [i for i in df.columns if i not in keepfields]
cfields = [i for i in df.columns if i.endswith("count")]
@jtrive84
jtrive84 / variable_association.py
Created January 28, 2020 20:50
Assess categorical association between nominal predictors.
import datetime
import itertools
import os
import os.path
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy import stats
from matplotlib.backends.backend_pdf import PdfPages
@jtrive84
jtrive84 / b_logistic_python.md
Last active December 4, 2023 18:27
Estimating Logistic Regression Coefficents From Scratch in Python

Estimating Logistic Regression Coefficents From Scratch in Python

In this post, we'll demonstrate how to estimate the coefficents of a Logistic Regression model using the Fisher Scoring algorithm in Python. We will then compare our estimates to those generated by scikit-learn’s linear_model.LogisticRegression class when fed the same dataset.

In a Generalized Linear Model, the response may have any distribution from the exponential family, and rather than assuming the mean is a linear function of the explnatory variables, we assume that a function of the mean, or the link function, is a linear function of the