def main():

    print("-- Classification Tree --")

    data = datasets.load_iris()
    X = data.data
    y = data.target

    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4)

    clf = ClassificationTree(max_features=2)
    clf.fit(X_train, y_train)
    y_pred = clf.predict(X_test)

    accuracy = accuracy_score(y_test, y_pred)
    print("Our DTClassifier Accuracy:", accuracy)

    clf = tree.DecisionTreeClassifier()
    clf.fit(X_train, y_train)
    y_pred = clf.predict(X_test)

    accuracy = accuracy_score(y_test, y_pred)
    print("sklearn DTClassifier Accuracy:", accuracy)
def main():
    print('-- Classification Tree')

    data = datasets.load_iris()
    X = data.data
    y = data.target

    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4)

    clf = ClassificationTree()
    clf.fit(X_train, y_train)
    y_pred = clf.predict(X_test)

    accuracy = accuracy_score(y_test, y_pred)

    print('Accuracy: ', accuracy)

    dt = DecisionTreeClassifier()
    dt.fit(X_train, y_train)
    y_val = dt.predict(X_test)

    acc = accuracy_score(y_test, y_val)

    print('sklearn score:', acc)
Esempio n. 3
0
            # dataset.append(Instance( [ncfr, dur, dfl, a3fl, a1fl, gr], [target] ))
        except Exception as e:
            pass

model = ClassificationTree()
X = standardize(X)
# X = RobustScaler(quantile_range=(25, 75)).fit_transform(X)
# X = MinMaxScaler().fit_transform(X)
# # # print y
datasets = k_fold_cross_validation_sets(X, y, 3)

for data in datasets:
    X_train, X_test, y_train, y_test = data
    model.fit(X_train, y_train)

    y_pred = model.predict(X_test)
    print(accuracy_score(y_test, y_pred))
    # print accuracy_score(y_test, y_pred)
    mse = mean_squared_error(y_test, y_pred)
    print("Mean Squared Error:", mse)
    # print (model.predict(np.array([[178, 0, 1000, 936]])))
    print(model.predict(np.array([[178, 0, 1000, 936, 855, 237000000, 0]])))

# model.print_tree()

filename = 'finalized_model.pikle'
pickle.dump(model, open(filename, 'wb'))

model_a = pickle.load(open(filename, 'rb'))

# print (model_a.predict(np.array([[178, 0, 1000, 936, 855, 237000000, 0]])))
Esempio n. 4
0
random_forest.fit(X_train, y_train)
print "\tSupport Vector Machine"
support_vector_machine.fit(X_train, rescaled_y_train)

# .........
#  PREDICT
# .........
y_pred = {}
y_pred["Adaboost"] = adaboost.predict(X_test)
y_pred["Naive Bayes"] = naive_bayes.predict(X_test)
y_pred["K Nearest Neighbors"] = knn.predict(X_test, X_train, y_train)
y_pred["Logistic Regression"] = logistic_regression.predict(X_test)
y_pred["LDA"] = lda.predict(X_test)
y_pred["Multilayer Perceptron"] = mlp.predict(X_test)
y_pred["Perceptron"] = perceptron.predict(X_test)
y_pred["Decision Tree"] = decision_tree.predict(X_test)
y_pred["Random Forest"] = random_forest.predict(X_test)
y_pred["Support Vector Machine"] = support_vector_machine.predict(X_test)

# ..........
#  ACCURACY
# ..........
print
print "Accuracy:"
for clf in y_pred:
    if clf == "Adaboost" or clf == "Support Vector Machine":
        print "\t%-23s: %.5f" % (clf,
                                 accuracy_score(rescaled_y_test, y_pred[clf]))
    else:
        print "\t%-23s: %.5f" % (clf, accuracy_score(y_test, y_pred[clf]))
print
Esempio n. 5
0


# .........
#  PREDICT
# .........
y_pred = {}
y_pred["Adaboost"] = adaboost.predict(X_test)
y_pred["Gradient Boosting"] = gbc.predict(X_test)
y_pred["Naive Bayes"] = naive_bayes.predict(X_test)
y_pred["K Nearest Neighbors"] = knn.predict(X_test, X_train, y_train)
y_pred["Logistic Regression"] = logistic_regression.predict(X_test)
y_pred["LDA"] = lda.predict(X_test)
y_pred["Multilayer Perceptron"] = mlp.predict(X_test)
y_pred["Perceptron"] = perceptron.predict(X_test)
y_pred["Decision Tree"] = decision_tree.predict(X_test)
y_pred["Random Forest"] = random_forest.predict(X_test)
y_pred["Support Vector Machine"] = support_vector_machine.predict(X_test)
y_pred["XGBoost"] = xgboost.predict(X_test)

# ..........
#  ACCURACY
# ..........

print ("Accuracy:")
for clf in y_pred:
	if clf == "Adaboost" or clf == "Support Vector Machine":
		print ("\t%-23s: %.5f" %(clf, accuracy_score(rescaled_y_test, y_pred[clf])))
	else:
		print ("\t%-23s: %.5f" %(clf, accuracy_score(y_test, y_pred[clf])))