Skip to content

Instantly share code, notes, and snippets.

View shaypal5's full-sized avatar
🐢
Working away...

Shay Palachy-Affek shaypal5

🐢
Working away...
View GitHub Profile
@shaypal5
shaypal5 / confusion_matrix_pretty_print.py
Last active May 13, 2024 13:04
Pretty print a confusion matrix with seaborn
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
def print_confusion_matrix(confusion_matrix, class_names, figsize = (10,7), fontsize=14):
"""Prints a confusion matrix, as returned by sklearn.metrics.confusion_matrix, as a heatmap.
Note that due to returning the created figure object, when this funciton is called in a
notebook the figure willl be printed twice. To prevent this, either append ; to your
function call, or modify the function by commenting out the return expression.
@shaypal5
shaypal5 / clique_percolation.py
Last active January 24, 2017 19:44
Clique percolation in Python with no external dependencies.
"""Finds communities in the given graph using clique percolation."""
def _add_edge_to_adjancy_list(adjancy_list, node1, node2):
if node1 in adjancy_list:
adjancy_list[node1].add(node2)
else:
adjancy_list[node1] = set([node2])
@shaypal5
shaypal5 / readme_content_in_sphinx.rst
Last active March 28, 2023 17:08
Including parts of README.rst in your sphinx docs
@shaypal5
shaypal5 / install-vim-from-sources-ubuntu.sh
Last active April 4, 2024 13:28
Installing Vim 8 on Ubuntu 16.04 LTS
# 1. install dependencies
sudo apt install libncurses5-dev libgnome2-dev libgnomeui-dev \
libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \
libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev \
python3-dev ruby-dev lua5.1 lua5.1-dev libperl-dev git
# 2. remove vim
sudo apt remove vim vim-runtime gvim
sudo apt remove vim-tiny vim-common vim-gui-common vim-nox
@shaypal5
shaypal5 / pandas_multindex_train_test_split.py
Created June 27, 2018 08:39
Use sklearn's train_test_split on the first level of a multi-indexed pandas DataFrame
import pandas as pd
from sklearn.model_selection import train_test_split
df = pd.DataFrame(data=[[1], [2], [3]], columns=['foo'], index=pd.MultiIndex.from_tuples(((0,'a'),(0, 'b'), (1, 'a'))))
train_ix, test_ix = train_test_split(df.index.levels[0])
train_df = df.loc[train_ix]
test_df = df.loc[test_ix]
@shaypal5
shaypal5 / chocobo_setup.py
Created July 9, 2018 17:20
An example setup.py file for the example chocobo package
"""Setup for the chocobo package."""
import setuptools
with open('README.md') as f:
README = f.read()
setuptools.setup(
author="Shay Palachy",
@shaypal5
shaypal5 / if_python_package.sh
Created July 21, 2018 17:00
bash if-else by Python package existence
# an example checking if the pandas package is installed
if python -c 'import pkgutil; exit(not pkgutil.find_loader("pandas"))'; then
echo 'pandas found'
else
echo 'pandas not found'
fi
@shaypal5
shaypal5 / quiet_print_oneliner.py
Created October 18, 2018 11:17
Silence-able print one-liner for Python
def foo(a, quiet=False):
_print = (lambda x: x) if quiet else print
b = a * 5
_print("Warming up warp engines. This will not print if quiet is set to True.")
return b + 3.14
@shaypal5
shaypal5 / Python packaging workshop requirements
Created February 13, 2019 05:03
Python packaging workshop requirements
pipenv
versioneer
pytest
coverage
pytest-cov
collective.checkdocs
pygments
wheel
twine
@shaypal5
shaypal5 / .travis.yml
Last active November 28, 2023 19:45
Comprehensive Python testing on Travis CI
language: python
# ===== Linux ======
os: linux
dist: xenial
python:
- 2.7
- 3.6
- 3.7
- 3.8
- 3.9