Beispiel #1
0
def randomForest():
    print("Random forest classifier")

    start = time.time()
    classifier = BinaryRelevance(classifier=RandomForestClassifier(),
                                 require_dense=[False, True])
    filename = "randomForest"

    classifier.fit(train_x, train_y)

    # save
    pickle.dump(classifier, open(filename, 'wb'))

    # load the model from disk
    classifier = pickle.load(open(filename, 'rb'))

    print('training time taken: ', round(time.time() - start, 0), 'seconds')

    predictions_new = classifier.predict(test_x)

    accuracy(test_y, predictions_new)
Beispiel #2
0
def supportVectorMachineChain():
    print("Support vector machine")

    start = time.time()
    classifier = ClassifierChain(classifier=svm.SVC(),
                                 require_dense=[False, True])
    filename = "SupportVectorMachine"

    classifier.fit(train_x, train_y)

    # save
    pickle.dump(classifier, open(filename, 'wb'))

    # load the model from disk
    classifier = pickle.load(open(filename, 'rb'))

    print('training time taken: ', round(time.time() - start, 0), 'seconds')

    predictions_new = classifier.predict(test_x)

    accuracy(test_y, predictions_new)
Beispiel #3
0
def knnBinary(m):
    print("knn binary")

    start = time.time()
    classifier = BinaryRelevance(KNeighborsClassifier(n_neighbors=m))

    filename = "knnBinary"

    classifier.fit(train_x, train_y)

    # save
    pickle.dump(classifier, open(filename, 'wb'))

    # load the model from disk
    classifier = pickle.load(open(filename, 'rb'))

    print('training time taken: ', round(time.time() - start, 0), 'seconds')

    predictions_new = classifier.predict(test_x)

    accuracy(test_y, predictions_new)
Beispiel #4
0
def knnClassifierChain():
    print("knn classifier chain")

    start = time.time()
    classifier = ClassifierChain(KNeighborsClassifier())

    filename = "knnChain"

    classifier.fit(train_x, train_y)

    # save
    pickle.dump(classifier, open(filename, 'wb'))

    # load the model from disk
    classifier = pickle.load(open(filename, 'rb'))

    print('training time taken: ', round(time.time() - start, 0), 'seconds')

    predictions_new = classifier.predict(test_x)

    accuracy(test_y, predictions_new)
Beispiel #5
0
def gaussianNaiveBayes():
    print("Gaussian naive bayes")

    start = time.time()
    classifier = ClassifierChain(GaussianNB())

    filename = "gaussianNaiveBayes"

    classifier.fit(train_x, train_y)

    # save
    pickle.dump(classifier, open(filename, 'wb'))

    # load the model from disk
    classifier = pickle.load(open(filename, 'rb'))

    print('training time taken: ', round(time.time() - start, 0), 'seconds')

    predictions_new = classifier.predict(test_x)

    accuracy(test_y, predictions_new)
Beispiel #6
0
def multinomialLogisticRegressionChain():
    # Train multi-classification model with logistic regression
    print("Logisticka regresija chain")

    start = time.time()
    classifier = BinaryRelevance(classifier=linear_model.LogisticRegression(
        multi_class='multinomial', solver='newton-cg'),
                                 require_dense=[False, True])

    filename = "logistickaRegresija.sav"
    classifier.fit(train_x, train_y)

    # save
    pickle.dump(classifier, open(filename, 'wb'))

    # load the model from disk
    classifier = pickle.load(open(filename, 'rb'))

    print('training time taken: ', round(time.time() - start, 0), 'seconds')

    predictions_new = classifier.predict(test_x)

    accuracy(test_y, predictions_new)