Skip to content

Instantly share code, notes, and snippets.

View matheushent's full-sized avatar
💭
Building things and repeating

Matheus Tosta matheushent

💭
Building things and repeating
View GitHub Profile
@matheushent
matheushent / NN.py
Last active January 29, 2019 14:45
Neural network for numbers classification
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('mnist/', one_hot=True)
X_train = mnist.train.images
y_train = mnist.train.labels
X_test = mnist.test.images
y_test = mnist.test.labels
@matheushent
matheushent / LWUE.py
Created February 5, 2019 13:12
Logistic regression using estimators
import pandas as pd
import numpy as np
base = pd.read_csv('census.csv')
# Transforming 'income' into 0 or 1
income = pd.get_dummies(base['income'], drop_first=True)
base.drop('income', axis=1, inplace=True)
@matheushent
matheushent / CNN.py
Created February 5, 2019 13:14
Convolution Neural Network
from tensorflow.examples.tutorials.mnist import input_data
import numpy as np
mnist = input_data.read_data_sets('mnist/', one_hot=False)
X_train = mnist.train.images
y_train = mnist.train.labels
X_test = mnist.test.images
y_test = mnist.test.labels
@matheushent
matheushent / CMBI.py
Created February 5, 2019 13:16
Iris classification
from sklearn import datasets
iris = datasets.load_iris()
X = iris.data
y = iris.target
from sklearn.preprocessing import StandardScaler
scaler_x = StandardScaler()
import warnings
warnings.filterwarnings('ignore')
import pandas as pd
import numpy as np
from tensorflow.python.keras import backend as K
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import InputLayer, Input
from tensorflow.python.keras.layers import Reshape, MaxPooling2D
from tensorflow.python.keras.layers import Conv2D, Dense, Flatten, Dropout
@matheushent
matheushent / Hyper-parameter Optimization with Lightgbm using skopt.py
Created February 20, 2019 23:59
Hyper-parameter optimization of xgboost model for Santander competition
from warnings import filterwarnings
filterwarnings('ignore')
import pandas as pd
import numpy as np
from lightgbm import LGBMClassifier
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score
import tensorflow as tf
import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data
import numpy as np
tf.reset_default_graph()
mnist = input_data.read_data_sets('mnist/', one_hot=True)
# Test
from tensorflow.examples.tutorials.mnist import input_data
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
mnist = input_data.read_data_sets('mnist/', one_hot=True)
X = mnist.train.images
# 784 -> 128 -> 64 -> 128 -> 784
@matheushent
matheushent / guided_relu.py
Created February 26, 2020 17:51 — forked from falcondai/guided_relu.py
Tensorflow implementation of guided backpropagation through ReLU
import tensorflow as tf
from tensorflow.python.framework import ops
from tensorflow.python.ops import gen_nn_ops
@ops.RegisterGradient("GuidedRelu")
def _GuidedReluGrad(op, grad):
return tf.select(0. < grad, gen_nn_ops._relu_grad(grad, op.outputs[0]), tf.zeros(grad.get_shape()))
if __name__ == '__main__':
with tf.Session() as sess:
@matheushent
matheushent / issue.py
Last active April 19, 2020 18:53
Stand alone code for tensorflow issue #38518
import tensorflow_addons as tfa
import tensorflow as tf
def get_norm_layer(norm):
"""Utility function to get the normalization layer
"""
if norm == None:
return lambda: lambda x: x
elif norm == 'batch_norm':