This file contains hidden or 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
| #Load libraries | |
| library(rjson) | |
| library(stringr) | |
| dfToJSON<-function(df, mode='vector'){ | |
| colToList<-function(x, y){ | |
This file contains hidden or 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
| ''' | |
| Created on Feb 6, 2014 | |
| @author: sraper | |
| ''' | |
| import itertools, urllib, urllib2, time, re, random | |
| from bs4 import BeautifulSoup | |
| def catchURL(queryURL): # Nicked this from someone. Afraid I can't remember who. Sorry |
This file contains hidden or 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 os | |
| dir = 'put your director in here' | |
| for filename in os.listdir(dir): | |
| with open(dir+filename, 'r') as fin: | |
| data = fin.read().splitlines(True) | |
| with open(dir+filename, 'w') as fout: | |
| fout.writelines(data[1:]) |
This file contains hidden or 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
| drop table if exists recommender_set_num; --In case you need to rerun the script | |
| drop table if exists person_ids_full_names; | |
| drop table if exists recom_names; | |
| -- Set up a table to load the recommendations data into | |
| create external table if not exists recommender_set_num | |
| ( | |
| userID bigint, | |
| itemID bigint | |
| ) row format delimited fields terminated by ',' |
This file contains hidden or 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
| x<-seq(1,10, by=0.1) | |
| y<-sin(x/4)+rnorm(91, 0,0.05) #Sin fucntion plus noise | |
| plot(x,y) | |
| #Knots at 2, 4 and 6 | |
| x2<-x^2 | |
| x3<-x^3 | |
| k1<-(x>2)*(x-2)^3 | |
| k2<-(x>4)*(x-4)^3 |
This file contains hidden or 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 os, csv | |
| progDir = '/pathToFolderContainingCSVs/' | |
| for filename in os.listdir(progDir): | |
| if filename != '.DS_Store': | |
| with open(progDir+filename, 'rb') as csvfile: | |
| progReader = csv.reader(csvfile, delimiter=',', quotechar='"') |
This file contains hidden or 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
| #Sequence for adding new data | |
| s<-seq(20,50, by=5) | |
| #Set up object for recording clusters | |
| clus.change<-NULL | |
| #Cycle through the clustering solutions | |
| for (i in s){ | |
| hc <- hclust(dist(USArrests[1:i,]), "ave") |
This file contains hidden or 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
| #Run hclust | |
| hc <- hclust(dist(USArrests[1:40,]), "ave") | |
| #Function for extracting nodes and links | |
| extractGraph<-function(hc){ | |
| n<-length(hc$order) | |
| m<-hc$merge | |
| links<-data.frame(source=as.numeric(), target=as.numeric(), value=as.numeric()) |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Tangle: a JavaScript library for reactive documents</title> | |
| <link rel="stylesheet" href="http://worrydream.com/Tangle/TangleKit/TangleKit.css" type="text/css"> | |
| <script type="text/javascript" src="http://worrydream.com/Tangle/TangleKit/mootools.js"></script> | |
| <script type="text/javascript" src="http://worrydream.com/Tangle/TangleKit/sprintf.js"></script> | |
| <script type="text/javascript" src="http://worrydream.com/Tangle/TangleKit/BVTouchable.js"></script> |
This file contains hidden or 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
| #Check the relationship between correlation and mutual information for binary vars | |
| store<-NULL | |
| for (i in 1:1000){ | |
| prob.1<-runif(1) | |
| prob.2<-runif(1) | |
| x<-rbinom(10000, 1, prob.1) | |
| y<-rbinom(10000, 1, prob.2) | |
| c<-cor(x,y) | |
| m<-mi.empirical(table(x,y)) | |
| store<-rbind(store, data.frame(c=c, m=m)) |
OlderNewer