
from sklearn import datasets
from random import shuffle

# This example loads the IRIS dataset and classifies
# using our neural network implementation.
# The results are visualized in a 2D-plot.

def main():
    iris = datasets.load_iris()
    X = iris.data
    Y = iris.target
    # Randomize (shuffle) the indexes
    # Shuffle randomizes idx in place
    idx = range(len(X))
    shuffle(idx)
    # Split the shuffled indexes into half, to training and test
    # The int conversion is needed in python 3, I think (for odd number of indexes)
    train_idx = idx[:int(len(idx)/2)]
    test_idx = idx[int(len(X)/2):]

if __name__=='__main__':
    main()


from sklearn import datasets
from random import shuffle
import numpy as np
from neuralnet import NeuralNet

# This example loads the IRIS dataset and classifies
# using our neural network implementation.
# The results are visualized in a 2D-plot.

def main():
    iris = datasets.load_iris()
    X = iris.data
    Y = iris.target
    # Randomize (shuffle) the indexes
    # Shuffle randomizes idx in place
    idx = range(len(X))
    shuffle(idx)
    # Split the shuffled indexes into half, to training and test
    # The int conversion is needed in python 3, I think (for odd number of indexes)
    train_idx = idx[:int(len(idx)/2)]
    test_idx = idx[int(len(X)/2):]
    # Initialize zero matrix for outputs in binary form
    Y_bin = np.zeros((len(Y),3),dtype=np.int)
    # Convert output from int to binary representation for neural network
    for i in range(len(Y)):
        Y_bin[i][Y[i]] = 1

if __name__=='__main__':
    main()

Convert output values from int to binary for neural network
Convert output values from int to binary for neural network

  
  from sklearn import datasets
  from random import shuffle
+ import numpy as np
+ from neuralnet import NeuralNet
  
  # This example loads the IRIS dataset and classifies
  # using our neural network implementation.
  # The results are visualized in a 2D-plot.
  
  def main():
      iris = datasets.load_iris()
      X = iris.data
      Y = iris.target
      # Randomize (shuffle) the indexes
      # Shuffle randomizes idx in place
      idx = range(len(X))
      shuffle(idx)
      # Split the shuffled indexes into half, to training and test
      # The int conversion is needed in python 3, I think (for odd number of indexes)
      train_idx = idx[:int(len(idx)/2)]
      test_idx = idx[int(len(X)/2):]
+     # Initialize zero matrix for outputs in binary form
+     Y_bin = np.zeros((len(Y),3),dtype=np.int)
+     # Convert output from int to binary representation for neural network
+     for i in range(len(Y)):
+         Y_bin[i][Y[i]] = 1
  
  if __name__=='__main__':
      main()
  
Convert output values from int to binary for neural network
## Code Before:

from sklearn import datasets
from random import shuffle

# This example loads the IRIS dataset and classifies
# using our neural network implementation.
# The results are visualized in a 2D-plot.

def main():
    iris = datasets.load_iris()
    X = iris.data
    Y = iris.target
    # Randomize (shuffle) the indexes
    # Shuffle randomizes idx in place
    idx = range(len(X))
    shuffle(idx)
    # Split the shuffled indexes into half, to training and test
    # The int conversion is needed in python 3, I think (for odd number of indexes)
    train_idx = idx[:int(len(idx)/2)]
    test_idx = idx[int(len(X)/2):]

if __name__=='__main__':
    main()

## Instruction:
Convert output values from int to binary for neural network
## Code After:

from sklearn import datasets
from random import shuffle
import numpy as np
from neuralnet import NeuralNet

# This example loads the IRIS dataset and classifies
# using our neural network implementation.
# The results are visualized in a 2D-plot.

def main():
    iris = datasets.load_iris()
    X = iris.data
    Y = iris.target
    # Randomize (shuffle) the indexes
    # Shuffle randomizes idx in place
    idx = range(len(X))
    shuffle(idx)
    # Split the shuffled indexes into half, to training and test
    # The int conversion is needed in python 3, I think (for odd number of indexes)
    train_idx = idx[:int(len(idx)/2)]
    test_idx = idx[int(len(X)/2):]
    # Initialize zero matrix for outputs in binary form
    Y_bin = np.zeros((len(Y),3),dtype=np.int)
    # Convert output from int to binary representation for neural network
    for i in range(len(Y)):
        Y_bin[i][Y[i]] = 1

if __name__=='__main__':
    main()
