Skip to content

Instantly share code, notes, and snippets.

@ClementC
ClementC / overfitting_illustration_generator.py
Created June 8, 2021 20:49
Small Python snippet to generate an illustration of the overfitting phenomenon
import numpy as np
import matplotlib.pyplot as plt
import warnings
np.random.seed(1) # This line is here to get a nice plot on the first try, you can comment it
warnings.simplefilter('ignore', np.RankWarning)
%matplotlib inline
# Main parameters
@ClementC
ClementC / search_and_replace_notion.py
Last active February 22, 2021 17:24
A small snippet to search and replace in all of your Notion.
import notion
from notion.client import NotionClient
from collections import Counter
from tqdm import tqdm
from pprint import pprint
from getpass import getpass
@ClementC
ClementC / search_and_replace_notion.py
Created June 12, 2020 09:57
A small snippet to search and replace in all of your Notion.
import notion
from notion.client import NotionClient
from collections import Counter
from tqdm import tqdm
from pprint import pprint
from getpass import getpass
@ClementC
ClementC / save_matplotlib_animation_from_notebook.py
Created October 16, 2018 14:19
Small script and descriptions of steps to extract a GIF for a matplotlib animation widget embedded in a Jupyter notebook.
# Matplotlib animations can be saved as a widget in a Jupyter notebook.
# It's unclear to how to recover it in Python once the notebook kernel has been restarted.
# But the image data is there in the notebook, embedded in a JS script in the output of the cell
# with the individual frames encoded as base64 png images.
# So here's the way I found to extract the images and make a GIF out of them.
# It's not all automatic and needs some manual action.
# Steps:
# 1/ Open the notebook in a web browser. Open the developer tools, and in the console, start typing "anim"
# then TAB to autocomplete. A variable with a unique name looking like "animae693007f74d44b0b917c61003e9490f" should appear.
# Cut this variable name, and copy it in the following command that you can then execute:
@ClementC
ClementC / cross_val_predict_issue.ipynb
Last active April 26, 2017 14:57
Minimal reproducible example with solutions proposals and benchmark.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ClementC
ClementC / check_twitter_followers.py
Created March 16, 2017 19:13
Checking user followed on Twitter to see which ones are not added to a list.
# coding: utf-8
import twitter
from tqdm import tqdm
from collections import defaultdict
import pickle
import pandas as pd
# Twitter API token
@ClementC
ClementC / print_cm.py
Last active September 5, 2017 07:08 — forked from zachguo/print_cm.py
from sklearn.metrics import confusion_matrix
def print_cm(cm, labels):
"""pretty print for confusion matrixes"""
columnwidth = max([len(x) for x in labels])
# Print header
print(" " * columnwidth, end="\t")
for label in labels:
print("%{0}s".format(columnwidth) % label, end="\t")
print()