Skip to content

Instantly share code, notes, and snippets.

"""
Code modified from https://jessesw.com/Data-Science-Skills/
Jeremy Karnowski August 30, 2015
"""
from bs4 import BeautifulSoup # For HTML parsing
import urllib2 # Website connections
import tldextract # Extracts domain information
import re # Regular expressions
from time import sleep # To prevent overwhelming the server between connections
@jkarnows
jkarnows / openai_cartpole_v0_dqn.py
Last active September 8, 2016 07:19 — forked from imironhead/openai_cartpole_v0_dqn.py
jkarnows-cartpole-v0-dqn
"""
Solve OpenAI Gym Cartpole V0 with DQN.
TensorFlow code by TiehHung Chuang (imironhead), 2016-09-06
tf-slim code by Jeremy Karnowski jkarnows, 2016-09-07
"""
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
@jkarnows
jkarnows / document_conversion.py
Created September 3, 2017 19:31
Converting .pdf, .doc, .docx, and .odt documents to .txt
from pylab import *
import urllib2
import twill
from twill.commands import *
import re
import os
import magic
import sys
from docx import *
@jkarnows
jkarnows / detcurve.py
Created September 3, 2017 19:35
Plotting a DET Curve
from matplotlib import pyplot as plt
def DETCurve(fps,fns):
"""
Given false positive and false negative rates, produce a DET Curve.
The false positive rate is assumed to be increasing while the false
negative rate is assumed to be decreasing.
"""
axis_min = min(fps[0],fns[-1])
fig,ax = plt.subplots()
plot(fps,fns)
@jkarnows
jkarnows / rpi_servo_control.py
Created September 3, 2017 19:46
Controlling the servos on a Raspberry Pi for a robot
from RPIO import PWM
servoLeft = 18 # 1300 is backwards, 1700 forward
servoRight = 23 # 1700 is backwards, 1300 forward
servo = PWM.Servo()
servo.set_servo(servoLeft,1500)
servo.set_servo(servoRight,1500)
@jkarnows
jkarnows / draw_circle.py
Created September 3, 2017 19:47
Drawing a circle with OpenCV
from cv2 import circle
# Input code here to determine the center of the circle, (x,y) and the radius.
color = (0,255,0)
thickness = 2
cv2.circle(img,(x,y),radius,color,thickness)
@jkarnows
jkarnows / loss_plot.py
Created September 3, 2017 19:54
Plotting training loss
import os
loss_files = sort(os.listdir('cv/'))
lfs = []
for lf in loss_files:
lf = map(float,lf[13:-3].split('_'))
lfs.append(lf)
lfs = array(sorted(lfs, key = lambda x: x[0]))
plot(lfs[:,0],lfs[:,1])
title('Training Lossn')
ylabel('Loss')
@jkarnows
jkarnows / idx-formatter.py
Last active September 3, 2017 20:07
Converting between binary files and directory of images
import numpy as np
# import cv2
import Image
import gzip
import os
import struct
def _read32(bytestream):
dt = np.dtype(np.uint32).newbyteorder('>')
return np.frombuffer(bytestream.read(4), dtype=dt)
Using Mac OS X El Capitan 10.11.6
sudo pip install virtualenv # Using Virtual Environment to contain dev environment
# [Navigate to folder rosetta-stone]
virtualenv rosetta # Create a virtual environment for this project
source rosetta/bin/activate # Start the virtual environment to install dev environment
pip install -U python # Install most recent Python
pip install numpy scipy matplotlib ipython pandas sympy nose # Install SciPy Stack
pip install sklearn # Install scikit-learn