Exemplo n.º 1
0
    print("Close the plot diagram to continue program")
    plt.show()

    ############################

    print('========== Visualize the Weights ==========')
    model = NeuralNetworks.NeuralNetworks(len(xTrain[0]), [2], 1)
    print('Training the model')
    for i in range(200):
        model.fit_one(xTrain, yTrain, 10, 0.05)
    hidden_layer_weights = model.weights[0]
    print('Output the weights')
    # for i in range(len(hidden_layer_weights)):
    #     weights = hidden_layer_weights[i]
    #     print(weights)
    Assignment5Support.VisualizeWeights(hidden_layer_weights[0],
                                        './weight-0.jpg')
    Assignment5Support.VisualizeWeights(hidden_layer_weights[1],
                                        './weight-1.jpg')

    ############################

    print('========== Find Underfitting and Overfiting ==========')
    fig, ax = plt.subplots()
    ax.grid(True)
    x = []
    for i in range(200):
        x.append(i)

    print(
        'Build Neural Network with 1 hidden layer, and 15 nodes for each layer'
    )
Exemplo n.º 2
0
#for numHiddenLayer in [1, 2]:
#	for numNodePerHiddenLayer in [2, 5, 10, 15, 20]:
#		print("Number of hidden layers: " + str(numHiddenLayer))
#		print("Number of nodes per hidden layer: " + str(numNodePerHiddenLayer))
#		if numHiddenLayer == 1:
#			model = NeuralNetStack.NeuralNetStack([len(trainingData[0][0]), numNodePerHiddenLayer, 1], .05, None)
#		else:
#			model = NeuralNetStack.NeuralNetStack([len(trainingData[0][0]), numNodePerHiddenLayer, numNodePerHiddenLayer, 1], .05, None)
#		model.fit(trainingData, 200, xTrain, yTrain, xTest, yTest)
#		(yPrediction, yPredictionProb) = model.predict(xTest)
#		print("This is test set accuracy")
#		Evaluations.ExecuteAll(yTest, yPrediction)
#
#		# Now this is train set accuracy
#		(yPrediction, yPredictionProb) = model.predict(xTrain)
#		print("This is train set accuracy")
#		Evaluations.ExecuteAll(yTrain, yPrediction)

model = NeuralNetStack.NeuralNetStack([len(trainingData[0][0]), 2, 1], .05,
                                      None)
model.fit(trainingData, 200, xTrain, yTrain, xTest, yTest)
firstNode = []
secondNode = []
for weights in model.weights[0]:
    firstNode.append(weights[0])
    secondNode.append(weights[1])

Assignment5Support.VisualizeWeights(firstNode, "firstNode.jpg")
Assignment5Support.VisualizeWeights(secondNode, "secondNode.jpg")