Skip to content

Instantly share code, notes, and snippets.

View ilovejs's full-sized avatar
🐡
mememe, hv a good fish !

Michael Zhuang ilovejs

🐡
mememe, hv a good fish !
  • Sydney
  • 22:23 (UTC +10:00)
View GitHub Profile
@ilovejs
ilovejs / gist:2935166
Created June 15, 2012 07:14 — forked from fxsjy/gist:2928683
bpnn solve kindergarten problem
# Back-Propagation Neural Networks
# another way: solve it as a Regression Problem
# Written in Python. See http://www.python.org/
# Modified by JSun to solve the problem here: http://www.weibo.com/1497035431/ynPEvC78V
# Neil Schemenauer <nas@arctrix.com>
import math
import random
import string
@ilovejs
ilovejs / gist:4214270
Created December 5, 2012 09:32 — forked from fxsjy/gist:3550053
Bakup Weibo to Disk
package main
import (
"net/http"
"net/url"
"log"
"io/ioutil"
"regexp"
"fmt"
//"net/http/httputil"
@ilovejs
ilovejs / svmflag.py
Created December 27, 2012 08:59 — forked from glamp/svmflag.py
import numpy as np
import pylab as pl
import pandas as pd
from sklearn import svm
from sklearn import linear_model
from sklearn import tree
from sklearn.metrics import confusion_matrix
@ilovejs
ilovejs / server.r
Created May 3, 2013 02:37 — forked from wch/server.r
if (!require(quantmod)) {
stop("This app requires the quantmod package. To install it, run 'install.packages(\"quantmod\")'.\n")
}
# Download data for a stock if needed, and return the data
require_symbol <- function(symbol, envir = parent.frame()) {
if (is.null(envir[[symbol]])) {
envir[[symbol]] <- getSymbols(symbol, auto.assign = FALSE)
}
#
# Get appraised value of car from Edmunds.com using the developer API with R
# Reference: http://developer.edmunds.com/docs/read/The_Vehicle_API
#
# set working dir
setwd('~/R/carvalue')
#load libraries
library(RJSONIO)
@ilovejs
ilovejs / global.R
Created February 15, 2014 02:44 — forked from hrbrmstr/global.R
library(shiny)
library(ggplot2)
library(RCurl)
library(reshape2)
#!/usr/bin/env ruby
# Please read http://otobrglez.opalab.com for more information about this code.
class Book < Struct.new(:title)
def words
@words ||= self.title.gsub(/[a-zA-Z]{3,}/).map(&:downcase).uniq.sort
end
# This method finds related articles using Jaccard index (optimized for PostgreSQL).
# More info: http://en.wikipedia.org/wiki/Jaccard_index
class Article < ActiveRecord::Base
def related(limit=10)
Article.find_by_sql(%Q{
SELECT
a.*,
( SELECT array_agg(t.name) FROM taggings tg, tags t

Movie Recommendations with k-Nearest Neighbors and Cosine Similarity


Introduction

The k-nearest neighbors (k-NN) algorithm is among the simplest algorithms in the data mining field. Distances / similarities are calculated between each element in the data set using some distance / similarity metric ^[1]^ that the researcher chooses (there are many distance / similarity metrics), where the distance / similarity between any two elements is calculated based on the two elements' attributes. A data element’s k-NN are the k closest data elements according to this distance / similarity.


1. A distance metric measures distance; the higher the distance the further apart the neighbors. A similarity metric measures similarity; the higher the similarity the closer the neighbors.