Skip to content

Instantly share code, notes, and snippets.

View noleto's full-sized avatar

Leonardo Noleto noleto

View GitHub Profile
@noleto
noleto / uci_bank_marketing_dataset_extract_timestamp.py
Last active August 27, 2018 12:45
UCI Bank Marketing Data Set - reverse engineering date from records (not given in the bank-additional-full data set)
## Data set in https://archive.ics.uci.edu/ml/datasets/bank+marketing does not contain timestamp.
## We can "deduce" them from the ordedr of records and use month and day_of_week columns to create a full date
## We know the first record was from 05-05-2008
import pandas as pd
import numpy as np
import datetime as dt
import sys
# read records from May 2008 to November 2010
@noleto
noleto / XGBoost+and+ELI5+-+prediction+does+not+match+sum+of+weights.ipynb
Created August 6, 2018 15:22
XGboost and ELI5 - misleading local feature contribution
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@noleto
noleto / gist:85643da1f7d7e5d5ca43a2308bc4d2f9
Created August 6, 2018 12:58
Plot High Resolution XGBoost Tree
xgb.plot_tree(booster, num_trees=1, rankdir='LR')
fig = matplotlib.pyplot.gcf()
fig.set_size_inches(80, 20)
fig.savefig('tree.png')
@noleto
noleto / lime_local_prediction_manual_calculation.py
Created August 1, 2018 15:39
LIME local prediction computed from weights of features
import numpy as np
import pandas as pd
import xgboost as xgb
from sklearn.model_selection import train_test_split
from sklearn.datasets import make_regression
import lime.lime_tabular
### make data
@noleto
noleto / shap_xgboost.py
Created August 1, 2018 10:39
using SHAP with XGBoost
# coding: utf-8
# In[1]:
### using XGBoost model with SHAP
import numpy as np
import pandas as pd
import xgboost as xgb
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" >> /etc/apt/sources.list.d/docker.list
sudo apt-get update
sudo apt-get purge lxc-docker
sudo apt-cache policy docker-engine
sudo apt-get install docker-engine
sudo service docker start
@noleto
noleto / install-mongo.sh
Last active January 1, 2016 06:09
Install latest MongoDB on Ubuntu
#!/bin/bash
#How to use it?
#wget -O- https://gist.github.com/noleto/8103292/raw/e6a77ef6faa0eab3676287b9a265a15b4d9edee3/install-mongo.sh | sh
LOG_TIME_FORMAT='date +%d-%m-%Y_%T'
echo "------------------------------------------"
echo "Install MongoDB on Ubuntu"
echo "------------------------------------------"
@noleto
noleto / stream_jcdecaux.sh
Created October 15, 2013 22:04
Un simple script pour requêter l'API JCDecaux et enregistrer les données dans un MongoDB
#!/bin/bash
MONGO=/path/install/mongo-db/bin
HOME=/path/jcdecaux/stockage
#Attention: changer le contrat Toulouse par celui de votre ville
status=$(curl -w %{http_code} -s 'https://api.jcdecaux.com/vls/v1/stations?contract=Toulouse&apiKey={cleAPI}' -o $HOME/all_stations.json $1)
if [ $status -ne 200 ]
then