Skip to content

Instantly share code, notes, and snippets.

View Olshansk's full-sized avatar
🦉

Daniel Olshansky Olshansk

🦉
View GitHub Profile
@Olshansk
Olshansk / transition_matricies_3.py
Created May 24, 2020 19:55
Transition Matricies - Regression Analysis
# Regression Analysis
fig, ax = plt.subplots(2, 1, figsize=(20,20))
sns.set(color_codes=True)
print("r2_score: ", round(r2_score(grades_GT, grades_P), 2))
print("mean_squared_error: ", round(mean_squared_error(grades_GT, grades_P), 2))
print("mean_absolute_error: ", round(mean_absolute_error(grades_GT, grades_P), 2))
print("explained_variance_score: ", round(explained_variance_score(grades_GT, grades_P), 2))
@Olshansk
Olshansk / joint_probability_matricies_3.py
Last active May 25, 2020 23:21
Joint Probability Matrices - Regression Analysis
# Regression Analysis
fig, ax = plt.subplots(2, 1, figsize=(20,20))
sns.set(color_codes=True)
print("mean_squared_error: ", round(mean_squared_error(grades_GT, grades_P), 2))
print("mean_absolute_error: ", round(mean_absolute_error(grades_GT, grades_P), 2))
print("explained_variance_score: ", round(explained_variance_score(grades_GT, grades_P), 2))
ax[0].tick_params(axis='both', labelsize=25)
@Olshansk
Olshansk / joint_probability_matricies_4.py
Last active May 25, 2020 23:22
Joint Probability Matrices - Create Transition Matrix Function
def create_joint_probability_matrix(data_GT, data_P, bins):
# https://stackoverflow.com/questions/38931566
def background_gradient(s, m=None, M=None, cmap='Reds', low=0, high=0):
if m is None:
m = s.min().min()
if M is None:
M = s.max().max()
rng = M - m
norm = colors.Normalize(m - (rng * low), M + (rng * high))
@Olshansk
Olshansk / joint_probability_matricies_5.py
Last active May 25, 2020 23:25
Joint Probability Matrix - Counts To Percentages
axis = np.linspace(5, 105, NUM_BINS + 1)[:-1]
jp_df = pd.DataFrame(jp_matrix, columns=axis, index=axis)
jp_df = jp_df.applymap(lambda val: 0 if math.isnan(val) else (val / NUM_STUDENTS))
jp_df
@Olshansk
Olshansk / joint_probability_matricies_6.py
Last active May 25, 2020 23:25
Joint Probability Matrices - Format Output Table
# https://stackoverflow.com/questions/38931566
def background_gradient(s, m=None, M=None, cmap='Reds', low=0, high=0):
if m is None:
m = s.min().min()
if M is None:
M = s.max().max()
rng = M - m
norm = colors.Normalize(m - (rng * low), M + (rng * high))
normed = s.apply(lambda x: norm(x.values))
cm = plt.cm.get_cmap(cmap)
@Olshansk
Olshansk / hot_reload_dockerfile_main.py
Created July 19, 2020 20:35
Hot Reload Dockerfile - Python Server File
from typing import Optional
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello2": "World5"}
@Olshansk
Olshansk / hot_reload_dockerfile.Dockerfile
Created July 19, 2020 20:36
Hot Reload Dockerfile - Dockerfile
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
WORKDIR /usr/src/
COPY ./src .
@Olshansk
Olshansk / hot_reload_dockerfile_docker_compose_no_volume.yaml
Last active July 19, 2020 20:52
Hot Reload Dockerfile - Docker Compose without Volume Mount
version: '3.7'
services:
server:
container_name: server
build:
context: .
dockerfile: Dockerfile
ports:
- "8008:8008"
environment:
@Olshansk
Olshansk / hot_reload_dockerfile_docker_compose_with_volume.yaml
Last active January 17, 2024 15:50
Hot Reload Dockerfile - Docker Compose with Volume Mount
version: '3.7'
services:
server:
container_name: server
build:
context: .
dockerfile: Dockerfile
volumes:
- ./src:/usr/src
ports:
import pandas as pd
from datetime import datetime, date
from iexfinance.stocks import get_historical_data
# Assumptions:
# 1. No missing data in existing dataframes in the store; data is complete between (date_min, date_max).
# 2. The requested data is of the same format (URL, params, retrieved columns, etc...).
# Reference for metadata: https://moonbooks.org/Articles/How-to-add-metadata-to-a-data-frame-with-pandas-in-python-/#store-in-a-hdf5-file
def get_historical_data_cached(store, symbol, start_date, end_date, **kwargs):