def eval_classification(X, y, q=20): X_train, X_test, y_train, y_test = testing.hold_out(X, y) W, M = train(X_train, y_train, q=q, activation=processing.sigmoid) D_teste = predict(X_test, W, M, activation=processing.sigmoid) y_test = processing.encode_label(y_test) y_pred = processing.encode_label(D_teste) acc = round(testing.accuracy(y_test, y_pred), ndigits=2) return acc
def eval_classification(X, y, q=Q): X_train, X_test, y_train, y_test = testing.hold_out(X, y, test_size=TEST_SIZE) T, G = train(X_train, y_train, q=q, activation=processing.sigmoid) D_teste = predict(X_test, T, G, activation=processing.sigmoid) y_test = processing.encode_label(y_test) y_pred = processing.encode_label(D_teste) acc = round(testing.accuracy(y_test, y_pred), ndigits=2) return acc
def main(): X, y = load.iris() X_train, X_test, y_train, y_test = testing.hold_out(X, y) W = train(X_train, y_train) y_pred = predict(X_test, W) y_test = processing.encode_label(y_test) acc = testing.accuracy(y_test, y_pred) print("ACC: {:.2f} %".format(acc * 100))
def predict(X, W): """Função de predição baseado na memória W da Rede Neural Perceptron. X é a matriz de features e não deve conter o bias, pois é adicionado nessa função. """ X = processing.add_bias(X) u = W.T @ X.T return processing.encode_label(u.T)
def score(self, X, y): y_pred = self.predict(X) y_encoded = processing.encode_label(y_pred) return testing.accuracy(y, y_encoded)
def predict(self, X): y_pred = predict(X, self.T, self.G, activation=self.activation) encoded = processing.encode_label(y_pred).astype(int) return encoded