Beispiel #1
0
def eval_classification(X, y, q=20):
    X_train, X_test, y_train, y_test = testing.hold_out(X, y)
    W, M = train(X_train, y_train, q=q, activation=processing.sigmoid)
    D_teste = predict(X_test, W, M, activation=processing.sigmoid)
    y_test = processing.encode_label(y_test)
    y_pred = processing.encode_label(D_teste)
    acc = round(testing.accuracy(y_test, y_pred), ndigits=2)
    return acc
Beispiel #2
0
def main():
    X, y = load.iris()
    X_train, X_test, y_train, y_test = testing.hold_out(X, y)
    W = train(X_train, y_train)
    y_pred = predict(X_test, W)
    y_test = processing.encode_label(y_test)
    acc = testing.accuracy(y_test, y_pred)

    print("ACC: {:.2f} %".format(acc * 100))
Beispiel #3
0
def eval_classification(X, y, q=Q):
    X_train, X_test, y_train, y_test = testing.hold_out(X,
                                                        y,
                                                        test_size=TEST_SIZE)
    T, G = train(X_train, y_train, q=q, activation=processing.sigmoid)
    D_teste = predict(X_test, T, G, activation=processing.sigmoid)
    y_test = processing.encode_label(y_test)
    y_pred = processing.encode_label(D_teste)
    acc = round(testing.accuracy(y_test, y_pred), ndigits=2)
    return acc
Beispiel #4
0
def main():
    # Train / test ELM
    print("-- Extreme Learning Machine")
    X, y = load.twomoons()
    q = 10
    (X_train, X_test, y_train, y_test) = testing.hold_out(X, y)
    W, M = elm.train(X_train, y_train, q=10, activation=processing.sigmoid)
    y_pred = elm.predict(X_test, W, M, activation=processing.sigmoid)
    y_pred = step(y_pred)
    acc = round(testing.accuracy(y_test, y_pred), ndigits=2)

    acc_text = "ACC={:.2f}%".format(acc * 100)
    print("X.shape: ", X.shape)
    print("y.shape: ", y.shape)
    print("W.shape:", W.shape)
    print("M.shape: ", M.shape)
    print(acc_text)

    ## SURFACE DECISON
    x1, x2 = X[:, 0], X[:, 1]
    x_min = min(min(x1), min(x2))
    x_max = max(max(x1), max(x2))
    n = 200
    linspace = np.linspace(x_min, x_max, n)

    points = []
    for xi in linspace:
        for xj in linspace:
            points.append((xi, xj))

    X_decision = np.array(points)
    y_elm = elm.predict(X_decision, W, M, activation=processing.sigmoid)
    x1_curve = []
    x2_curve = []
    for yi, p in zip(y_elm, points):
        if abs(yi) < 0.05:
            x1_curve.append(p[0])
            x2_curve.append(p[1])

    ax = plt.gca()
    ax.set_title("Two Moons: ELM / {}".format(acc_text))
    ax.set_xlabel("x1")
    ax.set_ylabel("x2")
    plt.scatter(x1_curve, x2_curve, c='k', s=1)
    plt.scatter(x1, x2, c=colorize(y))
    plt.show()
    plt.close()
Beispiel #5
0
 def score(self, X, y):
     y_pred = self.predict(X)
     y_encoded = processing.encode_label(y_pred)
     return testing.accuracy(y, y_encoded)