This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This gist solves the hard-margin SVM problem in three ways: using quadprog, using kernlab's ipop, and by | |
# the e1071 wrapper around libsvm. | |
# | |
# author: R. Walker (r_walker@zoho.com) | |
# LICENSE: MIT | |
library("quadprog") | |
library("kernlab") | |
library("e1071") | |
# Use Fisher iris data and binarize one of the species |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ipoptr_qp <- function(Dmat, dvec, Amat, bvec, ub=100){ | |
# Solve the quadratic program | |
# | |
# min -d^T x + 1/2 x^T D x | |
# s.t. A%*%x>= b | |
# | |
# with ipoptr. | |
n <- length(bvec) | |
# Jacobian structural components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import csv | |
from collections import defaultdict | |
# load the mapping (supplied by the dataset) from id into book_id | |
with open("goodreads/book_id_map.csv") as f: | |
reader = csv.reader(f) | |
_ = next(reader) | |
book_id_map = {int(_id): int(book_id) for _id, book_id in reader} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from scipy.sparse import coo_matrix, save_npz | |
import numpy as np | |
print("reading data...") | |
with open("goodreads/interactions.json") as f: | |
data = json.load(f) | |
books = data["books"] | |
interactions = data["interactions"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"s3:ListBucket" | |
], | |
"Resource": [ | |
"arn:aws:s3:::fancy-bucket" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import json | |
import sys | |
import warnings | |
import numpy as np | |
from scipy.sparse import load_npz, coo_matrix | |
class CooccurenceRecommender: | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# image segmentation demo | |
# author: rwalker (ryan@ryanwalker.us) | |
# license: MIT | |
library("jpeg") | |
library("png") | |
library("graphics") | |
library("ggplot2") | |
library("gridExtra") | |
####################################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.json4s.{DefaultFormats, Formats} | |
import scala.language.postfixOps | |
import scalate.ScalateSupport | |
import org.scalatra._ | |
import java.io.PrintWriter | |
class Chunks extends ScalatraServlet with ScalateSupport { | |
/* | |
Simple example of chunked transfer encoding in Scalatra (scala web framework) | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# This script is a simple introduction to the python elasticsearch API. | |
# | |
# This script will populate an elasticsearch index from a file and then give a simple command line query interface. | |
# Each line of the input file will be mapped into a JSON document of the form { "text": "my file line..." } and added | |
# to the index. | |
# | |
# You can use Docker to spin up a local elasticsearch instance to play around with, e.g. | |
# docker run --name elasticsearch -d -p 9200:9200 elasticsearch:latest | |
# |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.