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 April 25, 2024 07:37
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 / 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 / .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
@shaypal5
shaypal5 / bitbucket-pipelines.yml
Created July 30, 2020 13:14
Bitbucket status badges
image: python:3.8.3
# pipeline stages definitions
test: &test
step:
name: test
caches:
- pip
script:
- python --version
@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 / pdp_post_adv.py
Last active August 5, 2022 15:08
An example for an advanced initialization of a complex pdpipe pipeline for processing pandas dataframes. 🐼🚿
from typing import Optional
import pdpipe as pdp
from pdpipe import df
from sklearn.linear_model import LogisticRegression
from pdpipe.skintegrate import PdPipelineAndSklearnEstimator
class MyPipelineAndModel(PdPipelineAndSklearnEstimator):
def __init__(
self,
@shaypal5
shaypal5 / pdp_post_adv2.py
Last active August 1, 2022 17:36
An example for an advanced initialization of a complex pdpipe pipeline for processing pandas dataframes. 🐼🚿
>>> mp = MyPipelineAndModel(
savings_max_val=101,
drop_gender=False,
standardize=True,
ohencode_country=True,
savings_bin_val=1,
pca_threshold=25,
fit_intercept=True)
>>> mp
<PdPipeline -> LogisticRegression>
@shaypal5
shaypal5 / pdpipe_2nd_look.py
Last active July 9, 2022 16:06
Another minimal example of some pdpipe features.
>>> df = pd.DataFrame(
... [[23, 'Jo', 45], [19, 'Bo', 72], [15, 'Di', 12], [5, 'Jo', 0]],
... columns=['age', 'name', 'salary'])
>>> df
age name salary
0 23 Jo 45
1 19 Bo 72
2 15 Di 12
3 5 Jo 0
>>> pipeline = pdp.DropDuplicates('name').Bin({'salary': [0, 20, 50]}) \
@shaypal5
shaypal5 / funk_mf_recommender.py
Created July 1, 2022 10:34
A naive implementation of Funk's MF for collaborative filtering (commonly and wrongly called SVD for collaborative filtering). Might contain mistakes (let me know).
from typing import Tuple, Optional
import numpy as np
import pandas as pd
def train_val_split(
training_df: pd.DataFrame,
val_ratio: float,
) -> Tuple[pd.DataFrame, pd.DataFrame]:
"""Splits the input training dataset into train/val set.
@shaypal5
shaypal5 / pdpipe_first_look.py
Last active June 27, 2022 13:16
pdpipe first look
>>> df = pd.DataFrame(
data=[[4, 165, 'USA'], [2, 180, 'UK'], [2, 170, 'Greece']],
index=['Dana', 'Jane', 'Nick'],
columns=['Medals', 'Height', 'Born']
)
>>> df
Medals Height Born
Dana 4 165 USA
Jane 2 180 UK
Nick 2 170 Greece