Skip to content

Instantly share code, notes, and snippets.

View bbengfort's full-sized avatar
🎯
Focusing

Benjamin Bengfort bbengfort

🎯
Focusing
View GitHub Profile
@bbengfort
bbengfort / stream_count.go
Created July 10, 2019 14:47
Quick example of getting a stream in the btrdb-go bindings and counting the number of points
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/BTrDB/btrdb"
"github.com/PingThingsIO/smartgridstore/modules/creds"
@bbengfort
bbengfort / quickmethods.py
Last active September 25, 2019 13:47
An example of a quick method and a visualizer with detailed doc strings that discuss how best to create meaningful interactions between the two.
from sklearn.model_selection import train_test_split as tts
def visualizer(
model,
X_train,
y_train,
X_test=None,
y_test=None,
ax=None,
@bbengfort
bbengfort / btrdb_helpers.py
Last active June 4, 2019 17:35
BTrDB Helpers for common operations
import os
import time
import btrdb
from tabulate import tabulate
db = btrdb.connect("api.research.predictivegrid.com:4411", "48BE21A7A13661B1EED5AB87")
def list_collection(prefix):
@bbengfort
bbengfort / meta.yaml
Last active August 21, 2022 13:21
Yellowbrick example conda build meta.yaml file.
{% set name = "yellowbrick" %}
{% set version = "1.3" %}
{% set file_ext = "tar.gz" %}
{% set hash_type = "sha256" %}
{% set hash_value = "29eeedef78c2e5f37d05f558817b108108c34d72d37d0b05afdf969645b60ba1" %}
package:
name: '{{ name|lower }}'
version: '{{ version }}'
@bbengfort
bbengfort / colors.py
Created May 18, 2019 18:35
Argparse example of color conversion in SE 2019-05-18
#!/usr/bin/env python
def hex2rgb(color):
color = color.lstrip("#")
return tuple(
int(color[idx:idx+2], 16)
for idx in (0, 2, 4)
)
@bbengfort
bbengfort / crplot2.py
Created May 10, 2019 02:35
Classification report plots - code comparison.
#!/usr/bin/env python3
"""
Visual reports for classification models using matplotlib and scikit-learn.
"""
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split as tts
@bbengfort
bbengfort / crplot1.py
Last active May 10, 2019 02:07
Classification report plots - code comparison.
import numpy as np
import matplotlib.pyplot as plt
def plot_classification_report(cr, title='Classification report ', with_avg_total=False, cmap=plt.cm.Blues):
lines = cr.split('\n')
classes = []
plotMat = []
for line in lines[2 : (len(lines) - 3)]:
@bbengfort
bbengfort / codehead.py
Created May 1, 2019 13:34
Modifies the ID line of the code header at the top of Python files.
#!/usr/bin/env python
# codehead
# Scans the local directory if it's a git repository and adds the ID line.
#
# Author: Benjamin Bengfort <benjamin@bengfort.com>
# Created: Mon Mar 07 17:53:36 2016 -0500
#
# Copyright (C) 2016 Bengfort.com
# For license information, see LICENSE.txt
#
import numpy as np
import matplotlib.pyplot as plt
from yellowbrick.datasets import load_credit
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
# Load data from yellowbrick.datasets
X, y = load_credit()
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as grid
from mpl_toolkits.axes_grid1 import make_axes_locatable, axes_size
def joint_plot(x, y, ax=None):
"""
Create a square joint plot of x and y.