Skip to content

Instantly share code, notes, and snippets.

View jtrive84's full-sized avatar

James Triveri jtrive84

View GitHub Profile
@jtrive84
jtrive84 / is_prime.py
Created January 22, 2017 04:32
Function to determine if passed integer is prime
import math
def is_prime(n):
"""Determine if `n` is prime."""
if (n%2==0 or n%3==0): return(False)
threshold = math.floor(math.sqrt(n))
# all primes are of the form 6k+/-1 =>
plus_tst = any(n%i for i in
(6*k+1 for k in
@jtrive84
jtrive84 / Pip_Behind_Proxy.md
Last active March 29, 2023 09:21
How to download packages from pip behind a web proxy

Using pip behind a Web Proxy

pip is a package management system used primarily to install and maintain third-party libraries written for Python. pip will not work in an enterprise setting behind a web proxy without first setting environmental variables specifying the user's authentication details, in addition to the url and port of the proxy server. This post walks through how to setup and use pip from behind a web proxy on Windows.

Setting HTTP_PROXY & HTTPS_PROXY Environmental Variables

The first step is to set two environmental variables from the command line: HTTP_PROXY and HTTPS_PROXY. The required format is:

@jtrive84
jtrive84 / numpyIO.py
Created February 19, 2017 23:48
Reading dataset with genfromtxt (numpy)
import numpy as np
fpath = "challenger.csv"
# Setting dtype to `None` forces genfromtxt to determine
# the datatypes of each column =>
res = np.genfromtxt(fname=fpath,
dtype=None,
delimiter=",",
autostrip=True,
@jtrive84
jtrive84 / R_Packaging.ipynb
Created March 21, 2017 23:28
Creating R packages with devtools and roxygen2
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jtrive84
jtrive84 / Challenger.csv
Created March 21, 2017 23:40
O-ring failures in the 23 pre-Challenger space shuttle launches.
FLIGHT TEMPERATURE PRESSURE O_RING_FAILURE
1 66 50 0
2 70 50 1
3 69 50 0
4 68 50 0
5 67 50 0
6 72 50 0
7 73 100 0
8 70 100 0
9 57 200 1
@jtrive84
jtrive84 / Fisher_Scoring.R
Created May 31, 2017 01:35
Implementation of Fisher Scoring algorithm used to determine Logistic Regression coefficients when modeling a dataset with a dichotomous response.
### `getLogisticCoefficients_1` tracks the development of the coefficent vector and
### Information matrix across iterations, and identifies them as `information_progression`
### and coefficients_progression` in the returned list `returnList` ===>
getLogisticCoefficients_1 <- function(design_matrix, response_vector, epsilon=.0001) {
# ===================================================================
# design_matrix (X) => n-by-(p+1) |
# response_vector (y) => n-by-1 |
# probability_vector (p) => n-by-1 |
# weights_matrix (W) => n-by-n |
@jtrive84
jtrive84 / Logistic_Regression_Coefficient_Estimation.ipynb
Last active May 31, 2017 01:40
Demonstration of the use of iterative techniques in determining the coefficients of a Logistic Regression model
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jtrive84
jtrive84 / Normal_Equations.ipynb
Created May 31, 2017 01:42
Derivation of the Normal Equations using Least Squares and Maximum Likelihood
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jtrive84
jtrive84 / fisher_scoring.py
Created June 3, 2017 21:10
Fisher Scoring Algorithm (Python version)
def get_coefficients(design_matrix, response_vector, epsilon=.001):
"""
Determine Logistic Regression coefficents using Fisher Scoring algorithm.
Iteration ceases once changes between elements in coefficent matrix across
consecutive iterations is less than epsilon.
# =========================================================================
# design_matrix `X` => n-by-(p+1) |
# response_vector `y` => n-by-1 |
# probability_vector `p` => n-by-1 |
# weights_matrix `W` => n-by-n |
@jtrive84
jtrive84 / Fisher_Scoring.R
Created June 3, 2017 21:11
Fisher Scoring Algorithm (R version)
getCoefficients <- function(design_matrix, response_vector, epsilon=.0001) {
# =========================================================================
# design_matrix `X` => n-by-(p+1) |
# response_vector `y` => n-by-1 |
# probability_vector `p` => n-by-1 |
# weights_matrix `W` => n-by-n |
# epsilon => threshold above which iteration continues |
# =========================================================================
# n => # of observations |
# (p + 1) => # of parameterss, +1 for intercept term |