def validateTitanic():
    # Data
    X, Y = getDataValidation()

    # Network
    inputSize = 7
    layerCount = 2
    networkConf = nnConf.NeuralNetworkConf(inputSize, layerCount)
    networkConf.layerConf[0].neuronCount = 20
    networkConf.layerConf[0].activationFn = "relu"
    networkConf.layerConf[0].weightInitializerMethod = "random"
    networkConf.layerConf[1].neuronCount = 1
    networkConf.layerConf[1].activationFn = "sigmoid"
    networkConf.layerConf[1].weightInitializerMethod = "random"
    networkConf.Lambda = .00009      # 0.0001
    networkConf.maxIter = 500

    accuracyList = nnUtils.validateNN(X, Y, networkConf, 5, showLearning=False)

    print(accuracyList)
    print("Mean Accuracy: ", np.mean(accuracyList))

    # Store Neural network settings and state
#    print(NN.getGlobalConf())
#    print(networkConf)
    nnUtils.saveConfig(networkConf, nn.getGlobalConf())

    nnUtils.restoreConfig()

    accuracyList = []
    return (accuracyList)
def findBestInitialWeights():
    netConf, wrightsBias = runAndMeasure()

    netConfOld, wrightsBiasOld = nnUtils.restoreConfig("nn.json")

    print("New accuracy: ", netConf.accuracy)
    print("Old accuracy: ", netConfOld.accuracy)

    if netConf.accuracy > netConfOld.accuracy:
        # Store Neural network settings and state
        print("Got Better accuracy")
        nnUtils.saveConfig(netConf, wrightsBias, "nn.json")
Ejemplo n.º 3
0
def loadAndValidate(trainX, trainY):
    netConf, wrightsBias = nnUtils.restoreConfig("nn.json")

    accuracyList = nnUtils.validateNN(trainX,
                                      trainY,
                                      netConf,
                                      5,
                                      showLearning=False,
                                      wtReuse=True,
                                      wtAndBias=wrightsBias)

    print("Best accuracy on validation: ", np.mean(accuracyList))
def loadAndRun():
    # Data
    X, Y = getDataValidation()

    netConf, wrightsBias = nnUtils.restoreConfig("nn.json")

    accuracyList = nnUtils.validateNN(X, Y, netConf, 5,
                                      showLearning=False,
                                      wtReuse=True,
                                      wtAndBias=wrightsBias)

    print(accuracyList)
    print("Mean Accuracy: ", np.mean(accuracyList))
Ejemplo n.º 5
0
                                      showLearning=False)
    print("Initial Mean Accuracy: ", np.mean(accuracyList))

    #       * Run evaluation varying different network parameters with
    #         the fixed initial weights.
    #    netConf.Lambda, accuracy = getBestLambda(trainX, trainY, netConf)
    #    netConf.maxIter, accuracy = getBestMaxIter(trainX, trainY, netConf)
    netConf.Lambda = 0.0000946
    netConf.maxIter = 500
    print("Best Lambda: ", netConf.Lambda)
    print("Best MaxIter: ", netConf.maxIter)
    print("Best Config Mean Accuracy: ", np.mean(accuracyList))

    #   3. With the best network configuration get best set of Weights.
    #       * Run and store the best weights for the network configuration
    #         in above step.
    #   4. Goto step 3 until maximum accuracy is achieved.
    #    findAndStoreBestInitialWeights(trainX, trainY, netConf, 100)

    # 4.5. Validate with the best config
    loadAndValidate(trainX, trainY)

    #   5. Train the best model with training data and predict on test data.
    testX, PassengerId = getTestData()

    netConf, wrightsBias = nnUtils.restoreConfig("nn.json")

    trainAndPredict(trainX, trainY, testX, PassengerId, netConf, wrightsBias)

# That's all