Skip to content

Instantly share code, notes, and snippets.

View felipessalvatore's full-sized avatar

Felipe Salvatore felipessalvatore

View GitHub Profile
@felipessalvatore
felipessalvatore / tf_cl_iris.py
Created October 26, 2016 02:03
Multinomial logistic classifier applied to the iris dataset
#--------TENSORFLOW-------------
#MULTINOMIAL LOGISTIC CLASSIFIER
#APPLIED TO THE IRIS DATASET
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
import scipy as sp
from sklearn.datasets import load_iris
%matplotlib inline
@felipessalvatore
felipessalvatore / cosine.py
Created December 14, 2016 18:17
Calculating the cosine distance using scipy
import numpy as np
import scipy.spatial as ss
u = np.array([1,2,3])
u1 = np.array([1,2,3])
v = np.array([2,3,-4])
a = ss.distance.cosine(u, v)
a1 = ss.distance.cosine(u, u1)
@felipessalvatore
felipessalvatore / eig.py
Last active December 21, 2016 19:14
Calculating eigenvalues and eigenvectors in numpy
import numpy as np
from numpy import linalg as la
a = np.array([[3,1,1],[-1,3,1]],dtype='float32')
b = np.matmul(a,a.T)
eivalues, eivectors =la.eig(b)
#CAREFUL : the match is between the list
#of eigenvectors.T and eigenvalues
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email import encoders
fromaddr = "YOUR EMAIL"
toaddr = "EMAIL ADDRESS YOU SEND TO"
msg = MIMEMultipart()
@felipessalvatore
felipessalvatore / adorno.py
Created March 24, 2017 11:17
This is one of my first programs
x = float(input('Digite um número qualquer (positivo ou negativo): '))
y = str(input('Digite um substantivo precedido de seu artigo definido: '))
z = str(input('Digite um predicado que concorde em número e gênero com o substantivo: '))
if x > 0:
w = "Na sociedade dominada pela indústria cultural, "
k = "instante único"
u = " em si"
l = " Benjamin "
elif x < 0:
https://rdipietro.github.io/friendly-intro-to-cross-entropy-loss/
http://www.atmos.washington.edu/~dennis/MatrixCalculus.pdf
@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 ]")
@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 / 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