Skip to content

Instantly share code, notes, and snippets.

View jdmoore7's full-sized avatar
🏠
Working from home

Jacob Moore jdmoore7

🏠
Working from home
  • Chicago, IL
View GitHub Profile
@jdmoore7
jdmoore7 / logreg.py
Created December 9, 2019 16:58
python implementation of binary logistic regression
class LogReg():
"""
Implementation of binary logistic regression
"""
def __init__(self,dataframe,y_column):
"""
Initialize LogReg class with a pandas dataframe and the name of the dependent variable column, y.
All other variable will be assumed to be independent variables, x.
"""
@jdmoore7
jdmoore7 / LL.py
Created February 7, 2020 19:47
linked list python gist
class Node(object):
def __init__(self,val):
self.val = val
self.next = None
def get_data(self):
return self.val
def set_data(self,val):
self.val = val
@jdmoore7
jdmoore7 / generalTree.py
Created February 10, 2020 17:28
General Tree
class GeneralTree():
"""
Parameters:
@root: root node
@first_born: leftmost child of root node
@current_node: initalized as first born
@current-value: initialized as value of first born (current node)
@visited: Linked list of all values whichg have previously been visited
@path: FULL path, traversing siblings, from root to search value (LL)
@child_path: path, sibling traversal not captured, more closely resembles typical tree design/behavior (LL)
@jdmoore7
jdmoore7 / matrix_factorization.ipynb
Created February 19, 2020 15:16
matrix factorization via gradient descent from scratch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jdmoore7
jdmoore7 / MF.ipynb
Created February 19, 2020 15:50
MF
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jdmoore7
jdmoore7 / TweetGrabber.py
Created April 3, 2020 14:28
TweetGrabber
class TweetGrabber():
def __init__(self,myApi,sApi,at,sAt):
import tweepy
self.tweepy = tweepy
auth = tweepy.OAuthHandler(myApi, sApi)
auth.set_access_token(at, sAt)
self.api = tweepy.API(auth)
@jdmoore7
jdmoore7 / RetweetParser.py
Created April 3, 2020 14:42
RetweetParser
class RetweetParser():
def __init__(self,data,user):
import ast
self.user = user
edge_list = []
for idx,row in data.iterrows():
if len(row[4]) > 5:
@jdmoore7
jdmoore7 / TweetGraph.py
Last active April 3, 2020 15:41
TweetGraph
class TweetGraph():
def __init__(self,edge_list):
import igraph
import pandas as pd
data = pd.read_csv(edge_list).to_records(index=False)
self.graph = igraph.Graph.TupleList(data, weights=True, directed=False)
def e_centrality(self):
import operator
@jdmoore7
jdmoore7 / NBAlottery.py
Created May 28, 2020 12:51
NBA lottery monte carlo method
import random
def trial():
sequence = []
# dist = [0.140,0.140,0.140,0.125,0.105,0.090,0.075,0.060,0.045,0.030,0.020,0.015,0.010,0.005]
dist = [114,113,112,111,99,89,79,69,59,49,39,29,19,9,6,4]
pool = [idx+1 for idx,elem in enumerate(dist)]
# for i in range(4):
for i in range(5):
selected = random.choices(population=pool, weights=dist)[0]
@jdmoore7
jdmoore7 / pr_ncaa_acc.py
Created May 30, 2020 16:39
NCAA_page_rank_gist
# SQL
import sqlite3
conn = sqlite3.connect('acc1819.db')
c = conn.cursor()
# Get columns from game table
game_columns = c.execute("""
PRAGMA table_info(games);
""").fetchall()
g_col = [game_columns[i][1] for i in range(len(game_columns))]