Skip to content

Instantly share code, notes, and snippets.

View horsehour's full-sized avatar
🏠
Working from home

Chunheng Jiang horsehour

🏠
Working from home
View GitHub Profile
import importlib
import os
from urllib import request
import tensorflow as tf
import numpy as np
import json
import base64
import networkx as nx
from typing import Sequence, Dict, Union, Tuple, Any, List
@arose13
arose13 / install-conda.sh
Last active May 5, 2025 08:31
Install Miniconda in Ubuntu
# Setup Ubuntu
sudo apt update --yes
sudo apt upgrade --yes
# Get Miniconda and make it the main Python interpreter
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p ~/miniconda
rm ~/miniconda.sh
export PATH=~/miniconda/bin:$PATH
@ytsaig
ytsaig / custom_subsampling.py
Created February 21, 2017 12:54
Reproducible example for custom subsampling with LightGBM
import lightgbm as lgb
import numpy as np
import pandas as pd
from sklearn.metrics import mean_squared_error
def custom_subsample(n, frac):
"""Subsample frac*n indices."""
return np.random.choice(n, int(n*frac), replace=False)
# load data
import sys
def get_size(obj, seen=None):
"""Recursively finds size of objects"""
size = sys.getsizeof(obj)
if seen is None:
seen = set()
obj_id = id(obj)
if obj_id in seen:
return 0
@jdfekete
jdfekete / README.md
Last active April 14, 2024 12:23
Matrix diagram that visualizes character co-occurrences in Victor Hugo’s "Les Misérables"

Source: The Stanford GraphBase

A network can be represented by an adjacency matrix, where each cell ij represents an edge from vertex i to vertex j. Here, vertices represent characters in a book, while edges represent co-occurrence in a chapter.

Given this two-dimensional representation of a graph, a natural visualization is to show the matrix! However, the effectiveness of a matrix diagram is heavily dependent on the order of rows and columns: if related nodes are placed closed to each other, it is easier to identify clusters and bridges.

This example lets you try different orderings via the drop-down menu. This type of diagram can be extended with manual reordering of rows and columns, and expanding or collapsing of clusters, to allow deeper exploration. Jacques Bertin (or more specifically, his fleet of assistants) did this by hand with

@borella
borella / gist:11285316
Created April 25, 2014 10:48
Google Chrome with local file access on Mac OS X
open /Applications/Google\ Chrome.app --args --allow-file-access-from-files