def __net_input(self, X):
        return np.dot(X, self.w_[1:]) + self.w_[0]

    def __activation(self, X):
        return self.__sigmoid(X)

    def predict(self, X):
        # 1- Calculate the net input W^T * x
        z = self.__net_input(X)
        # 2- Return the activated values (0 or 1 classes)
        return np.where(self.__activation(z) >= 0.5, 1, 0)
        pass


reader = CsvReader("./data/Iris.csv")

iris_features, iris_labels = reader.get_iris_data()

ignore_verginica = [
    i for i, v in enumerate(iris_labels) if v == 'Iris-virginica'
]
iris_features = [
    v for i, v in enumerate(iris_features) if i not in ignore_verginica
]
iris_labels = [
    v for i, v in enumerate(iris_labels) if i not in ignore_verginica
]

print(len(iris_features))
print(len(iris_labels))
Ejemplo n.º 2
0
from data_reader.reader import CsvReader
from util import *

import tensorflow as tf
import matplotlib.pyplot as plt
import math

reader = CsvReader(
    "/home/ahani/PycharmProjects/IrisClassification/data/Iris.csv")

iris_features, iris_labels = reader.get_iris_data()
iris_features, iris_labels = shuffle(iris_features, iris_labels)
binarized_labels = binarize_labels(iris_labels)

INPUT_NEURONS = 4
HIDDEN_NEURONS = 200
OUTPUT_NEURONS = 3

NUM_OF_EPOCHS = 1000

x = tf.placeholder(tf.float32, [None, INPUT_NEURONS])
y_target = tf.placeholder(tf.float32, [None, OUTPUT_NEURONS])

input_hidden_weights = tf.Variable(
    tf.random_uniform([INPUT_NEURONS, HIDDEN_NEURONS],
                      -1.0 / math.sqrt(INPUT_NEURONS), 1.0 /
                      math.sqrt(INPUT_NEURONS)))  #Ini from the given network
input_hidden_bias = tf.Variable(tf.ones([HIDDEN_NEURONS]))  # The bias in one
hidden_neurons_values = tf.matmul(x, input_hidden_weights) + input_hidden_bias
hidden_activation_result = tf.nn.softmax(hidden_neurons_values)
    def __net_input(self, X):
        return np.dot(X, self.w_[1:]) + self.w_[0]

    def __activation(self, X):
        return self.__sigmoid(X)

    def predict(self, X):
        # 1- Calculate the net input W^T * x
        z = self.__net_input(X)
        # 2- Return the activated values (0 or 1 classes)
        h = self.__activation(z)
        return np.where(self.__activation(z) >= 0.5, 1, 0)


reader = CsvReader("./data/titanic/train.csv")

titanic_features, titanic_labels = reader.get_titanic_data()

print(len(titanic_features))
print(len(titanic_labels))

#titanic_labels = to_onehot(titanic_labels)
#titanic_labels = list(map(lambda v: v.index(max(v)), titanic_labels))

train_x, train_y, test_x, test_y = titanic_features[0:712], titanic_labels[
    0:712], titanic_features[712:], titanic_labels[712:]
train_x, train_y, test_x, test_y = np.asarray(train_x), np.asarray(
    train_y), np.asarray(test_x), np.asarray(test_y)

train_x, means, stds = standardize(train_x)
from data_reader.reader import CsvReader
from util import *

import tensorflow as tf
import matplotlib.pyplot as plt
import math

reader = CsvReader("/home/ahani/PycharmProjects/IrisClassification/data/Iris.csv")

iris_features, iris_labels = reader.get_iris_data()
iris_features, iris_labels = shuffle(iris_features, iris_labels)
binarized_labels = binarize_labels(iris_labels)

INPUT_NEURONS = 4
HIDDEN_NEURONS = 200
OUTPUT_NEURONS = 3

NUM_OF_EPOCHS = 1000

x = tf.placeholder(tf.float32, [None, INPUT_NEURONS])
y_target = tf.placeholder(tf.float32, [None, OUTPUT_NEURONS])

input_hidden_weights = tf.Variable(
                tf.random_uniform([INPUT_NEURONS, HIDDEN_NEURONS], -1.0 / math.sqrt(INPUT_NEURONS), 1.0 / math.sqrt(INPUT_NEURONS))) #Ini from the given network
input_hidden_bias = tf.Variable(tf.ones([HIDDEN_NEURONS])) # The bias in one
hidden_neurons_values = tf.matmul(x, input_hidden_weights) + input_hidden_bias
hidden_activation_result = tf.nn.softmax(hidden_neurons_values)

hidden_output_weights = tf.Variable(
                tf.random_uniform([HIDDEN_NEURONS, OUTPUT_NEURONS], -1.0 / math.sqrt(HIDDEN_NEURONS), 1.0 / math.sqrt(HIDDEN_NEURONS)))
hidden_output_bias = tf.Variable(tf.ones([OUTPUT_NEURONS])) # The bias in one