コード例 #1
0
def main1():
    """
    Now, take N = 10. After finding the weights using Linear Regression,
    use them as a vector of initial weights for the Perceptron Learning Algorithm. Run PLA until it converges
    to a final vector of weights that completely separates all the in-sample points. Among the choices below,
    what is the closest value to the average number of iterations (over 1000 runs) that PLA takes to converge?
    (When implementing PLA,
    have the algorithm choose a point randomly from the set of misclassified points at each iteration)
    """
    EXP_TIMEs = 1000
    train_num = 10
    iterations_list = []
    for e in range(EXP_TIMEs):
        w, X_train, Y_train = generate_date(train_num)
        lr = LinearRegression(X_train, Y_train)
        lr.learn_w()
        learned_w = lr.w
        #def __init__(self, training_X, training_Y, init_w=[]):
        per = Perceptron(X_train, Y_train, learned_w)
        per.gd_algorithm()
        iterations_list.append(per.num_iterations)
    print(avg(iterations_list))
コード例 #2
0
def main1():
    """
    Now, take N = 10. After finding the weights using Linear Regression,
    use them as a vector of initial weights for the Perceptron Learning Algorithm. Run PLA until it converges
    to a final vector of weights that completely separates all the in-sample points. Among the choices below,
    what is the closest value to the average number of iterations (over 1000 runs) that PLA takes to converge?
    (When implementing PLA,
    have the algorithm choose a point randomly from the set of misclassified points at each iteration)
    """
    EXP_TIMEs = 1000
    train_num = 10
    iterations_list = []
    for e in range(EXP_TIMEs):
        w, X_train, Y_train = generate_date(train_num)
        lr = LinearRegression(X_train, Y_train)
        lr.learn_w()
        learned_w = lr.w
        #def __init__(self, training_X, training_Y, init_w=[]):
        per = Perceptron(X_train, Y_train, learned_w)
        per.gd_algorithm()
        iterations_list.append(per.num_iterations)
    print(avg(iterations_list))