Skip to content

Instantly share code, notes, and snippets.

View fnielsen's full-sized avatar

Finn Årup Nielsen fnielsen

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fnielsen
fnielsen / mixedindexing.py
Last active November 16, 2019 04:00
Mixed indexing with integer index in Pandas DataFrame
import pandas as pd
df = pd.DataFrame([[1, 2, 's'], [3, 4, 't'], [4, 5, 'u']],
index=[-1, 0, 1], columns=['a', 'b', 'c'])
>>> df.a # Correct type
-1 1
0 3
1 4
Name: a, dtype: int64
@fnielsen
fnielsen / Combining embedding methods for a word intrusion task.ipynb
Last active March 22, 2019 19:52
Jupyter notebook for a small study on embedding methods on a Danish word intrusion task
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fnielsen
fnielsen / hellocherry.py
Created October 2, 2012 13:16
CherryPy Hello World
# http://docs.cherrypy.org/stable/concepts/basics.html
import cherrypy
class HelloWorld:
def index(self):
return "Hello world!"
index.exposed = True
cherrypy.quickstart(HelloWorld())
"""
Usage:
Nielsen2017Linking_camera.py
Notes
-----
This script demonstrates the use of Wikidata together with
ImageNet-based deep learning classifiers. It relates to the manuscript
"Linking ImageNet WordNet Synsets with Wikidata" from 2018.
@fnielsen
fnielsen / gist:1410094
Created November 30, 2011 18:12
Movie review sentiment classifier and the AFINN word list
# Code inspired and developed from:
# http://streamhacker.com/2010/05/10/text-classification-sentiment-analysis-naive-bayes-classifier/
from __future__ import division
import nltk.classify, nltk.corpus, nltk.classify.util
from pylab import *
filebase = '/home/fn'
@fnielsen
fnielsen / gist:3826666
Created October 3, 2012 12:24
CherryPy vs Tornado benchmarking
#########
# Tornado
wget https://raw.github.com/facebook/tornado/master/demos/helloworld/helloworld.py
python helloworld.py
# 100 concurrent
ab -c 100 -n 1000 -k localhost.localdomain:8888/ | grep "Time taken for tests:"
# Time taken for tests: 0.709 seconds
# 5 concurrent
@fnielsen
fnielsen / awesome
Created July 17, 2014 19:35
Awesome
import re
import requests
import pandas as pd
import matplotlib.pyplot as plt
pd.Series({re.findall('^(.+)\n', section)[0]: len(re.findall('^\*', section, flags=re.MULTILINE)) for section in re.split('^##[^#]', requests.get('https://raw.githubusercontent.com/josephmisiti/awesome-machine-learning/master/README.md').text, flags=re.MULTILINE)[1:-1]}).plot(kind='barh', title="'Awesome' machine learning links")
plt.show()
@fnielsen
fnielsen / gist:1373887
Created November 17, 2011 17:50
Co-author mining for papers in the Brede Wiki
import matplotlib.pyplot as plt
import networkx as nx
from pysqlite2 import dbapi2
connection = dbapi2.Connection('bredewiki-templates.sqlite3')
sql = "SELECT DISTINCT pid FROM brede WHERE (template='paper' OR template='conference_paper');"
cursor = connection.cursor()
cursor.execute(sql)
pids = [ row[0] for row in cursor.fetchall() ]
@fnielsen
fnielsen / gist:1392607
Created November 25, 2011 01:29
Computation of co-author distance in the Brede Wiki co-author graph
# wget http://neuro.imm.dtu.dk/services/bredewiki/download/bredewiki-templates.sqlite3
import matplotlib.pyplot as plt
import networkx as nx
from pysqlite2 import dbapi2
connection = dbapi2.Connection('bredewiki-templates.sqlite3')
sql = "SELECT DISTINCT tid FROM brede WHERE (template='paper' OR template='conference_paper');"
cursor = connection.cursor()
cursor.execute(sql)
tids = [ row[0] for row in cursor.fetchall() ]