Skip to content

Instantly share code, notes, and snippets.

View zhiyzuo's full-sized avatar
😂
what is this?

Zhiya Zuo zhiyzuo

😂
what is this?
View GitHub Profile
@zhiyzuo
zhiyzuo / data.csv
Created February 8, 2020 13:32
a test dataset
x1 x2 x3 x4 x5
18.111123267989484 0.9413535720603655 blue 21.461557236715407 24.564564564564563
20.777182965390768 0.9254882601025508 red 50.9811019286979 42.1021021021021
16.419984794385705 0.30857677822338525 blue 6.708702983134573 30.36036036036036
13.491654081695486 0.7397988735986664 red 9.37693608222175 46.75675675675676
18.94383945783266 0.04137615910651404 green 25.216686004245922 28.85885885885886
6.905085356512098 0.8934767495838009 green 6.062177604293495 23.843843843843842
19.195264404503213 0.00404794853091317 green 38.934832457935734 28.31831831831832
24.136736612950912 0.1469761380555349 red 67.99375967919259 30.99099099099099
21.369679538896957 0.5368152632079091 green 26.116198203606416 32.73273273273273
@zhiyzuo
zhiyzuo / .bash_profile
Created October 18, 2018 15:50
A minimal `.bash_profile` file for MSCI 3250
# Add Homebrew `/usr/local/bin` and User `~/bin` to the `$PATH`
#PATH=$HOME/bin:$PATH
export PATH=/usr/local/bin:$PATH
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
export PATH="/usr/local/opt/sqlite/bin:$PATH"
export PATH="/usr/local/opt/openssl/bin:$PATH"
@zhiyzuo
zhiyzuo / my_regmodel.py
Last active September 23, 2018 22:26
a wrapper function for linear regression analysis using statsmodels
import pandas as pd
import statsmodels.formula.api as smf
from statsmodels.stats.outliers_influence import variance_inflation_factor
def get_vif(data):
d = {data.columns.values[i]: variance_inflation_factor(data.values, i)\
for i in range(data.shape[1])}
vif_series = pd.Series(d)
return vif_series
@zhiyzuo
zhiyzuo / get_coef_table.py
Created May 20, 2018 21:54
Obtain regression model coefficients from statsmodels
import pandas as pd
def get_coef_table(lin_reg):
''' lin_reg is a fitted statsmodels regression model
Return a dataframe containing coefficients, pvalues, and the confidence intervals
'''
err_series = lin_reg.params - lin_reg.conf_int()[0]
coef_df = pd.DataFrame({'coef': lin_reg.params.values[1:],
'ci_err': err_series.values[1:],
'pvalue': lin_reg.pvalues.round(4).values[1:],
@zhiyzuo
zhiyzuo / notebook_init.py
Last active September 29, 2020 04:16
A gist to save my init code in Jupyter notebooks
import numpy as np
import scipy as sp
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
%matplotlib inline
@zhiyzuo
zhiyzuo / pearsonr_ci.py
Last active January 4, 2023 06:19
calculate Pearson correlation along with the confidence interval using scipy and numpy
import numpy as np
from scipy import stats
def pearsonr_ci(x,y,alpha=0.05):
''' calculate Pearson correlation along with the confidence interval using scipy and numpy
Parameters
----------
x, y : iterable object such as a list or np.array
Input for correlation calculation
@zhiyzuo
zhiyzuo / jsd.py
Last active May 12, 2022 10:58
Jensen-Shannon Divergence in Python
import numpy as np
import scipy as sp
def jsd(p, q, base=np.e):
'''
Implementation of pairwise `jsd` based on
https://en.wikipedia.org/wiki/Jensen%E2%80%93Shannon_divergence
'''
## convert to np.array
p, q = np.asarray(p), np.asarray(q)
@zhiyzuo
zhiyzuo / Data-for-Research.md
Last active September 16, 2017 05:40
Data resource

This gist will be a place for some interesting data source I found but have no time to collect/think about yet.

__author__ = "Zhiya Zuo"
__email__ = "zhiyazuo@gmail.com"

Toy/Experimental datasets

This section lists datasets to play with or experiment with (e.g., test/evaluate/validate/learn new algorithms.)

@zhiyzuo
zhiyzuo / Install-Rattle-on-macOS.md
Last active May 17, 2020 12:17
A brief note on how to install rattle/RGtk2 on macOS