def check_svm_gamma(gamma):
    X_train_std, X_test_std, y_train, y_test = get_data_std()
    X_combined_std, y_combined = create_combined_data(X_train_std, X_test_std,
                                                      y_train, y_test)
    svm = SVC(kernel='rbf', random_state=0, gamma=gamma, C=1.0)
    svm.fit(X_train_std, y_train)
    plot_decision_regions(X_combined_std,
                          y_combined,
                          classifier=svm,
                          test_idx=range(105, 150))
    plt.xlabel('petal length [standardized]')
    plt.ylabel('petal width [standardized]')
    plt.legend(loc='upper left')
    plt.show()
def k_neighbor_classify():
    X_train_std, X_test_std, y_train, y_test = get_data_std()
    X_combined_std, y_combined = create_combined_data(X_train_std, X_test_std,
                                                      y_train, y_test)
    knn = KNeighborsClassifier(n_neighbors=5, p=2, metric='minkowski')
    knn.fit(X_train_std, y_train)
    plot_decision_regions(X_combined_std,
                          y_combined,
                          classifier=knn,
                          test_idx=range(105, 150))
    plt.xlabel('petal length [standardized]')
    plt.ylabel('petal width [standardized]')
    plt.legend(loc='upper left')
    plt.show()
def support_vector_machine():
    X_train_std, X_test_std, y_train, y_test = get_data_std()
    X_combined_std, y_combined = create_combined_data(X_train_std, X_test_std,
                                                      y_train, y_test)

    svm = SVC(kernel='linear', C=10.0, random_state=0)
    svm.fit(X_train_std, y_train)
    plot_decision_regions(X_combined_std,
                          y_combined,
                          classifier=svm,
                          test_idx=range(105, 150))
    plt.xlabel('petal length [standardized]')
    plt.ylabel('petal width [standardized]')
    plt.legend(loc='upper left')
    plt.show()
Esempio n. 4
0
def create_random_forest_structure():
    X_train, X_test, y_train, y_test = get_data()
    X_combined, y_combined = create_combined_data(X_train, X_test, y_train,
                                                  y_test)
    forest = RandomForestClassifier(criterion='entropy',
                                    n_estimators=10,
                                    random_state=1,
                                    n_jobs=2)
    forest.fit(X_train, y_train)
    plot_decision_regions(X_combined,
                          y_combined,
                          classifier=forest,
                          test_idx=range(105, 150))
    plt.xlabel('petal length [cm]')
    plt.ylabel('petal width [cm]')
    plt.legend(loc='upper left')
    plt.show()
Esempio n. 5
0
def create_tree_structure(output_file):
    X_train, X_test, y_train, y_test = get_data()
    tree = DecisionTreeClassifier(criterion='entropy',
                                  max_depth=3,
                                  random_state=0)
    tree.fit(X_train, y_train)
    X_combined, y_combined = create_combined_data(X_train, X_test, y_train,
                                                  y_test)
    plot_decision_regions(X_combined,
                          y_combined,
                          classifier=tree,
                          test_idx=range(105, 150))
    export_graphviz(tree,
                    out_file=output_file,
                    feature_names=['petal length', 'petal width'])
    plt.xlabel('petal length [cm]')
    plt.ylabel('petal width [cm]')
    plt.legend(loc='upper left')
    plt.show()