Skip to content

Instantly share code, notes, and snippets.

Avatar
😂
what is this?

Zhiya Zuo zhiyzuo

😂
what is this?
View GitHub Profile
@zhiyzuo
zhiyzuo / data.csv
Created Feb 8, 2020
a test dataset
View data.csv
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
View msci3250-mac-guide.md
@zhiyzuo
zhiyzuo / .bash_profile
Created Oct 18, 2018
A minimal `.bash_profile` file for MSCI 3250
View .bash_profile
# 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 Sep 23, 2018
a wrapper function for linear regression analysis using statsmodels
View my_regmodel.py
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
Obtain regression model coefficients from statsmodels
View get_coef_table.py
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 Sep 29, 2020
A gist to save my init code in Jupyter notebooks
View notebook_init.py
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 Oct 6, 2020
calculate Pearson correlation along with the confidence interval using scipy and numpy
View pearsonr_ci.py
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 18, 2021
Jensen-Shannon Divergence in Python
View jsd.py
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)
View Data-for-Research.md

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
A brief note on how to install rattle/RGtk2 on macOS
View Install-Rattle-on-macOS.md