Skip to content

Instantly share code, notes, and snippets.

View felipessalvatore's full-sized avatar

Felipe Salvatore felipessalvatore

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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])])