Skip to content

Instantly share code, notes, and snippets.

View thiagomarzagao's full-sized avatar

Thiago Marzagão thiagomarzagao

View GitHub Profile
import re
import math
import pickle
import logging
import gensim
import numpy as np
import pandas as pd
from casenames import casenames
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level = logging.INFO, filename = 'output.log')
import pickle
import gensim
import logging
import pandas as pd
from casenames import casenames
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level = logging.INFO, filename = 'output.log')
# set number of topics
num_topics = 50
import os
import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestRegressor
from sklearn.ensemble import ExtraTreesRegressor
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import AdaBoostRegressor
# set input path (path to LSA or LDA results)
ipath = '/home/ubuntu/results/lsa/results.csv'
casenames = [
'Afghanistan1992',
'Afghanistan1993',
'Afghanistan1994',
'Afghanistan1995',
'Afghanistan1996',
'Afghanistan1997',
'Afghanistan1998',
'Afghanistan1999',
'Afghanistan2000',
@thiagomarzagao
thiagomarzagao / ads.py
Created May 30, 2014 04:51
Code used for my "Automated Democracy Scores" paper.
#!/usr/bin/env python
import os
import time
import pickle
import numpy as np
import pandas as pd
# set paths
basepath = '/fs/lustre/osu6994/hdf5/'
@thiagomarzagao
thiagomarzagao / dimensao.do
Created May 30, 2014 05:42
Code used for my paper "A dimensao geografica das eleicoes brasileiras".
* extracting variance estimates by state (to be used in R)
reg pt2 party lgdpcap bolsagdp rural illiteracy nonadequate AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO
predict double eps, residual
robvar eps, by(state)
by state, sort: egen sd_eps = sd(eps)
generate double gw_wt = 1/sd_eps^2
tabstat sd_eps gw_wt, by(state)
* running initial diagnostics (obs.: failed; too many observations for spatwmat)
@thiagomarzagao
thiagomarzagao / dimensao.R
Created May 30, 2014 05:44
Code used for my paper "A dimensao geografica das eleicoes brasileiras".
### preliminary stuff
setwd("/Users/thiagomarzagao/desktop/PROJECT")
library(foreign)
library(MASS)
library(car)
library(lmtest)
library(spdep)
library(sphet)
library(Matrix)
library(spgwr)
'''
parse (HTML -> JSON) e-Compras GDF content
'''
import os
import re
import json
import socket
from bs4 import BeautifulSoup
@thiagomarzagao
thiagomarzagao / index.html
Created February 1, 2015 20:04
plot Brazil
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 1160;
@thiagomarzagao
thiagomarzagao / catmat_svm.py
Created December 5, 2015 20:19
código p/ treinar classificador SVM p/ CATMAT
import os
import pickle
from sklearn.utils import shuffle
from sklearn import linear_model
from sklearn import cross_validation
# carrega X
with open('X.pkl', mode = 'rb') as fbuffer:
X = pickle.load(fbuffer)