Skip to content

Instantly share code, notes, and snippets.

View felipessalvatore's full-sized avatar

Felipe Salvatore felipessalvatore

View GitHub Profile
@felipessalvatore
felipessalvatore / hash_basic.py
Created October 25, 2016 12:57
Hash table in python
#Num momento do Assigment 1 precisei comparar duas arrays de arrays
#com um número grande de elementos. Fazer um loop duplo é custoso demais.
#Uma saida que achei no forum foi usar o hash do python. Assim, geramos um
#código único para cada array e comparamos os códigos e não as arrays.
#exemplo:
import hashlib
a = np.arrange([np.arrange([1,2]),np.arrange([2,2]), np.arrange([3,2])])
b = np.arrange([np.arrange([1,2]),np.arrange([2,222]), np.arrange([3333,2])])
@felipessalvatore
felipessalvatore / li_re.py
Created October 25, 2016 12:59
linear regression algorithm in python
import matplotlib
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
%matplotlib inline
features = np.array([0.8,0.9,1.0,1.1,1.4,\
@felipessalvatore
felipessalvatore / mult_lo_re.py
Created October 25, 2016 13:07
multinomial logistic regression
#APPLIED TO THE IRIS DATASET
import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
import os
from sklearn.linear_model import LogisticRegression
from six.moves import cPickle as pickle
from sklearn.datasets import load_iris
%matplotlib inline
@felipessalvatore
felipessalvatore / lfd_pla.py
Created October 25, 2016 13:12
Exercise LFD and PLA (Perceptron learning Algorithm)
import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
import os
from sklearn.linear_model import LogisticRegression
from six.moves import cPickle as pickle
from sklearn.datasets import load_iris
%matplotlib inline
@felipessalvatore
felipessalvatore / first_nn.py
Created October 25, 2016 13:14
First try in training a neural network in python
import random
import numpy as np
import matplotlib.pyplot as plt
from pylab import norm
class BasicNN:
bias = 0.5
weights = []
@felipessalvatore
felipessalvatore / soft_max.py
Created October 25, 2016 13:16
First softmax function in python
#SOFTMAX FUNCTION
import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
import os
from sklearn.linear_model import LogisticRegression
from six.moves import cPickle as pickle
from sklearn.datasets import load_iris
%matplotlib inline
@felipessalvatore
felipessalvatore / trans_ma_one.py
Last active October 26, 2016 01:49
Transform matrix in lists and classes in one hot encoding
#ARRAY TRANSFORMATION
import numpy as np
#o melhor modo de transformar uma lista de matrizes n x n
# em uma lista de listas de tamanho n*n eh
def reformat(lista,n):
lista = lista.reshape((-1, n*n)).astype(np.float32)
@felipessalvatore
felipessalvatore / basic_pickle.py
Created October 25, 2016 13:25
Basic pickle manipulation in python
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>saving
import pickle
a = 1
b = [23,4,4,22]
c = "Hello"
d = "Baby I got me"
e = 99999
@felipessalvatore
felipessalvatore / ve_ba_cla.py
Created October 25, 2016 13:26
Very basic class creation in python
class Conta:
#Exemplo mais simples de classe"
#Como inicialiar o objeto de uma classe"
def __init__(self):
self.data = []
self.saldo = 2200
self.ano = 2016
self.nome = "Felipe"
def f(self,z):
@felipessalvatore
felipessalvatore / open_image.py
Created October 25, 2016 13:27
Open an image in Jupyter notebook
from IPython.display import Image
Image(filename="nome do arquivo")