Esempio n. 1
0
def predict_base_mlp(input_data, validation_data, test_data, filename):
    inputX = input_data.iloc[:, 0:1024]  # Binary features (first 1024 columns)
    inputY = input_data.iloc[:,
                             1024]  # Index representing the class (last column)

    # Create a decision tree fit using the training data
    basemlp = MLPClassifier(100, activation='logistic', solver='sgd')
    basemlp.fit(inputX, inputY)

    # Validate decision tree. But we aren't calibrating any parameters so this is optional.
    validX = validation_data.iloc[:, 0:1024]
    validY = validation_data.iloc[:, 1024]
    score = basemlp.score(validX, validY)
    print(f'Score on validation set: {score}')

    # Predict using the test data
    testX = test_data.iloc[:, 0:1024]
    testY = test_data.iloc[:, 1024]
    predictions = basemlp.predict(testX)
    score2 = basemlp.score(testX, testY)

    # Print the predictions to CSV
    output_df = pd.DataFrame(predictions)
    output_df.transpose()
    fileutils.write_output(filename, output_df)

    return predictions, testY
Esempio n. 2
0
def predict_gnb(input_data, validation_data, test_data, filename):
    inputX = input_data.iloc[:, 0:1024]  # Binary features (first 1024 columns)
    inputY = input_data.iloc[:,
                             1024]  # Index representing the class (last column)

    # Create a GNB fit using the training data
    gnb = GaussianNB()
    gnb.fit(inputX, inputY)

    # Validate GNB. But we aren't calibrating any parameters so this is optional.
    validX = validation_data.iloc[:, 0:1024]
    validY = validation_data.iloc[:, 1024]
    score = gnb.score(validX, validY)
    print(f'Score: {score}')

    # Predict using the test data
    testX = test_data.iloc[:, 0:1024]
    testY = test_data.iloc[:, 1024]
    predictions = gnb.predict(testX)

    # Print the predictions to CSV
    output_df = pd.DataFrame(predictions)
    output_df.transpose()
    fileutils.write_output(filename, output_df)

    return predictions, testY
Esempio n. 3
0
def predict_best_mlp(input_data, validation_data, test_data, filename):
    inputX = input_data.iloc[:,0:1024] # Binary features (first 1024 columns)
    inputY = input_data.iloc[:,1024] # Index representing the class (last column)

    # Create a mlp fit using the training data
    basemlp = MLPClassifier(**best_mlp_params(input_data))
    basemlp.fit(inputX, inputY)

    # Validate the mlp.
    validX = validation_data.iloc[:, 0:1024]
    validY = validation_data.iloc[:,1024]
    score = basemlp.score(validX, validY)
    print(f'Score on validation set: {score}')

    # Predict using the test data
    testX = test_data.iloc[:,0:1024]
    testY = test_data.iloc[:,1024]
    predictions = basemlp.predict(testX)
    score2 = basemlp.score(testX, testY)
    
    # Print the predictions to CSV
    output_df = pd.DataFrame(predictions)
    output_df.transpose()
    fileutils.write_output(filename, output_df)

    return predictions, testY
Esempio n. 4
0
def predict_perceptron(input_data, validation_data, test_data, filename):
    inputX = input_data.iloc[:, 0:1024]  # Binary features (first 1024 columns)
    inputY = input_data.iloc[:,
                             1024]  # Index representing the class (last column)

    # Create a perceptron fit using the training data
    perceptron = Perceptron()
    perceptron.fit(inputX, inputY)

    # Validate perceptron
    validX = validation_data.iloc[:, 0:1024]
    validY = validation_data.iloc[:, 1024]
    score = perceptron.score(validX, validY)
    print(f'Score on validation set: {score}')

    # Predict using the test data
    testX = test_data.iloc[:, 0:1024]
    testY = test_data.iloc[:, 1024]
    predictions = perceptron.predict(testX)
    score2 = perceptron.score(testX, testY)

    # Print the predictions to CSV
    output_df = pd.DataFrame(predictions)
    output_df.transpose()
    fileutils.write_output(filename, output_df)

    return predictions, testY