Skip to content

Instantly share code, notes, and snippets.

View felipessalvatore's full-sized avatar

Felipe Salvatore felipessalvatore

View GitHub Profile
@felipessalvatore
felipessalvatore / temporal_plot.py
Created December 17, 2017 14:28
Plotting a temporal series using matplotlib
import matplotlib.pyplot as plt
from datetime import date
#data
logic_tuple = [(1936, 3), (1937, 6), (1938, 3), (1939, 5),
(1940, 2), (1941, 2), (1942, 7), (1943, 1),
(1944, 2), (1945, 2), (1947, 2), (1948, 4),
(1949, 7), (1950, 3), (1951, 2), (1952, 5),
@felipessalvatore
felipessalvatore / lr_plot_ex.py
Created November 18, 2017 13:09
visual example of linear regression
from sklearn import linear_model
import numpy as np
import matplotlib.pyplot as plt
# generating fake linear data.
# Where x = square meter, y = house price
cond = False
while not cond:
@felipessalvatore
felipessalvatore / jupyter.md
Last active October 28, 2017 15:57
remote jupyter

Setting Jupyter in a remote computer

In REMOTE

i) create config file

$ jupyter notebook --generate-config

ii) create password

@felipessalvatore
felipessalvatore / points_with_label.py
Last active October 27, 2017 19:02
Plot points with numerical label in seaborn and latex title
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib import rc
sns.set_style("darkgrid")
# for using latex in plt it requires one installation:
# $ sudo apt install dvipng
rc('font', **{'family': 'sans-serif', 'sans-serif': ['Helvetica']})
@felipessalvatore
felipessalvatore / strided_slice.py
Created September 29, 2017 18:46
tf_gist: strided_slice
# strided_slice(
# input_,
# begin,
# end,
# strides=None,
# begin_mask=0,
# end_mask=0,
# ellipsis_mask=0,
# new_axis_mask=0,
# shrink_axis_mask=0,
@felipessalvatore
felipessalvatore / range_input_producer.py
Created September 29, 2017 17:24
script to grasp what the idea behind the range_input_producer
# range_input_producer(
# limit,
# num_epochs=None,
# shuffle=True,
# seed=None,
# capacity=32,
# shared_name=None,
# name=None)
# Produces the integers from 0 to limit-1 in a queue.
@felipessalvatore
felipessalvatore / tf_queue1.py
Last active September 28, 2017 15:18
Exploring queue tensorflow 1
import numpy as np
import tensorflow as tf
NUM_THREADS = 4
data = np.array([[0.2, 0.3], [0.4, 0.9], [0.8, -1.2], [-1.3, -0.2]])
target = np.array([1, 0, 1, 0])
queue = tf.FIFOQueue(capacity=3,
dtypes=[tf.float32, tf.int32],
@felipessalvatore
felipessalvatore / gradient_descent.py
Last active July 6, 2022 05:35
Plotting a 3d image of gradient descent in Python
#code adapted from http://tillbergmann.com/blog/python-gradient-descent.html
%matplotlib inline
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from scipy import stats
from sklearn.datasets.samples_generator import make_regression
@felipessalvatore
felipessalvatore / infotheory.py
Created September 5, 2017 16:40
basic function from information theory
import numpy as np
import random
import unittest
from math import isnan
def softmax(x):
"""
Compute the softmax function for each row of the input x.
It is crucial that this function is optimized for speed because
@felipessalvatore
felipessalvatore / mem.py
Created August 4, 2017 14:10
memory debug Python
import tracemalloc
tracemalloc.start()
# ... run your application ...
snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('lineno')
print("[ Top 10 ]")