Skip to content

Instantly share code, notes, and snippets.

@opoyraz
opoyraz / dbir_patterns.py
Created June 15, 2020 04:42 — forked from tbyers-risklens/dbir_patterns.py
DBIR Patterns for verispy package
import pandas as pd
def get_pattern(df):
""" Generates the DBIR "patterns," with liberal inspiration from the getpatternlist.R:
https://gist.github.com/jayjacobs/a145cb87551f551fc719
Parameters
----------
df: pd DataFrame with most VERIS encodings already built (from verispy package).
@opoyraz
opoyraz / stats.py
Created January 12, 2020 03:51 — forked from benjaminmgross/stats.py
Predicted R-Squared (r2, r^2) Calculation in `python`
def press_statistic(y_true, y_pred, xs):
"""
Calculation of the `Press Statistics <https://www.otexts.org/1580>`_
"""
res = y_pred - y_true
hat = xs.dot(np.linalg.pinv(xs))
den = (1 - np.diagonal(hat))
sqr = np.square(res/den)
return sqr.sum()