Пример #1
0
    dataSet = x
    for i in range(len(dataSet)):
        X = dataSet[i][1]
        Y = dataSet[i][2]
        Z = dataSet[i][3]
        if y[i] == 1:
            p = ax.scatter(X, Y, Z, c='c', marker='^')
        else:
            p2 = ax.scatter(X, Y, Z, c='r', marker='o')
    ax.legend([p, p2], ['Label 1 data', 'Label -1 data'])
    xs, ys = np.meshgrid(np.arange(-0.2, 1.2, 0.02),
                         np.arange(-0.2, 1.2, 0.02))
    zs = -(w[0] + w[1] * xs + w[2] * ys) / w[3]
    ax.plot_surface(xs, ys, zs, color='b', alpha=0.3)
    plt.show()


if __name__ == '__main__':
    X, Y = inputData("classification.txt")
    X = np.c_[np.ones(len(X)), np.array(X)]
    pla = Perceptron()
    pla.n_iter = 5000
    print(pla.get_params())
    pla = pla.fit(X, Y)
    accuracy = pla.score(X, Y)
    W = pla.coef_
    print('Accuracy =', accuracy)
    print('Weights =', W)
    display(X, Y, W[0])
Пример #2
0
    plt.ylabel('Error number')
    plt.show()
    # Waiting to implement
    pass


if __name__ == '__main__':
    """
    PLA
    """
    X, Y = getInputData("classification.txt")
    X = np.c_[np.ones(len(X)), np.array(
        X
    )]  # Coordinates vector of points, which is added '1' at first column.
    pla = Perceptron()
    pla.n_iter = 200
    info = pla.get_params()
    print(info)
    pla = pla.fit(X, Y)
    score = pla.score(X, Y)
    W = pla.coef_
    print('score =', score)
    print('W=', W)
    plot(X, Y, W[0])
    """
    pocket PLA
    """
    iterList = []
    numList = []
    best_score = 0
    W = None
Пример #3
0
"""
Created on Wed Apr 19 11:22:19 2017

@author: 3200183
"""

print(__doc__)

from sklearn import clone
from sklearn.linear_model import Perceptron
from sklearn.tree import DecisionTreeClassifier
import numpy as np
import matplotlib.pyplot as plt
from arftools import *
model = Perceptron()
model.n_iter = 1000
#model = DecisionTreeClassifier()
#model.max_depth=3

(X,y) =   gen_arti(centerx=1, centery=1, sigma=0.1, nbex=1000, data_type=1, epsilon=0.02)

d= np.ones(len(X))/len(X)

print len(d) 
print len(y)

res = []
eps = 0.1
step=0
while eps <0.5 and eps>0 and step<100:
    print(step)