text_plain_output_1.png
from sklearn.model_selection  import train_test_split

import numpy as np

import pandas

dataframe = pandas.read_csv('../input/ecoli.csv', delim_whitespace=True)
dataframe.columns = ['seq_name', 'mcg', 'gvh', 'lip', 'chg', 'aac', 'alm1', 'alm2', 'site']
dataframe = dataframe.drop('seq_name', axis=1)
dataframe.site.replace(('cp', 'im', 'pp', 'imU', 'om', 'omL', 'imL', 'imS'), (1, 0, 0, 0, 0, 0, 0, 0), inplace=True)
dataset = dataframe.values
DataX = np.array(dataset[:, 0:7])
DataY = np.transpose([dataset[:, 7]])

X_train, X_test, Y_train, Y_test = train_test_split(DataX, DataY, test_size=0.2)

def intialize_parameters(n_x, n_h, n_y):
    np.random.seed(4)
    W1 = np.random.randn(n_h, n_x)
    W2 = np.random.randn(n_y, n_h)
    parameters = {'W1': W1, 'W2': W2}
    return parameters

def intialize_parameters_deep(layer_dims):
    np.random.seed(4)
    L = len(layer_dims)
    parameters = {}
    for l in range(1, L):
        parameters['W' + str(l)] = np.random.randn(layer_dims[l], layer_dims[l - 1])
    return parameters

parameters = intialize_parameters_deep([7, 4, 3])

def linear_forward(A, W):
    Z = np.dot(W, A.T)
    cache = (A, W)
    return (Z, cache)

Z, cache = linear_forward(X_train, parameters['W1'])

def sigmoid(Z):
    A = 1 / (1 + np.exp(-Z))
    cache = Z
    return (A, cache)
def relu(Z):
    A = np.maximum(0, Z)
    cache = Z
    return (A, cache)

A, cache = sigmoid(Z)
A, cache = relu(Z)

def linear_activation_forward(A_prev, W, activation):
    if activation == 'sigmoid':
        Z, linear_cache = linear_forward(A_prev, W)
        A, activation_cache = sigmoid(Z)
    if activation == 'relu':
        Z, linear_cache = linear_forward(A_prev, W)
        A, activation_cache = relu(Z)
    cache = (linear_cache, activation_cache)
    return (A, cache)

A, cache = linear_activation_forward(X_train, parameters['W1'], 'sigmoid')
print(A.shape)
A, cache = linear_activation_forward(X_train, parameters['W1'], 'relu')
print(A.shape)