def main():
    data = load_data.load('data2.txt')
    X = data[:, 0:2]
    print('X is \n{0}\n'.format(X))
    print('mean(X) is {0}'.format(np.mean(X, axis=0)))
    print('std(X) is {0}'.format(np.std(X, axis=0)))
    print('normalization of X is\n {0}'.format(normalize.normalize(X)))
Ejemplo n.º 2
0
def main():
    data = load_data.load('data1.txt')
    X = data[:, 0]
    Y = data[:, 1]
    plot_data.plot(X, Y, 'house size', 'house price', {
        'show': True,
        'title': 'Original Data',
        'fmt': 'rx'
    })
def main():
    X, y, origin_X = load_data.load_and_process('data1.txt')
    initial_theta = np.zeros(X.shape[1])
    res = minimize(cost_function, initial_theta, args=(X, y), method=None, jac=gradient, options={'maxiter': 400})
    print(res)

    theta = res.x

    data = load_data.load('data1.txt')

    pos_values = data[(data[:, 2] == 1)]
    neg_values = data[(data[:, 2] == 0)]

    plot_data.plot(pos_values[:, 0], pos_values[:, 1], 'score1', 'score2',
                   {
                       'fmt': 'bx',
                       'markersize': 5
                   })

    plot_data.plot(neg_values[:, 0], neg_values[:, 1], 'score1', 'score2',
                   {
                       'fmt': 'yo',
                       'markersize': 5,
                       'show': False
                   })

    score1 = np.linspace(25, 100)
    score2 = []
    for item in score1:
        score2.append(((0.5 - theta[0]) - theta[1] * item) / theta[2])
    score2 = np.array(score2)

    plot_data.plot(score1, score2, 'score1', 'score2',
                   {
                       'fmt': 'r-',
                       'label': 'minimize',
                       'show': False
                   })

    theta_from_cal = np.array([-4.81180027, 0.04528064, 0.03819149]) # 0.001 10 0000
    theta_from_cal_2 = np.array([-15.39517866, 0.12825989, 0.12247929]) # 0.001 100 0000
    theta_from_cal_3 = np.array([-22.21628108, 0.18268725, 0.17763448]) # 0.003 100 0000
    score3 = []
    for item in score1:
        score3.append(((0.5 - theta_from_cal_3[0]) - theta_from_cal_3[1] * item) / theta_from_cal_3[2])
    score3 = np.array(score3)
    plot_data.plot(score1, score3, 'score1', 'score2',
                   {
                       'fmt': 'g-',
                       'label': 'gredient-descent',
                       'legend_loc': 'upper right',
                       'show': True
                   })

    print(predict(45, 85, theta_from_cal_3))
Ejemplo n.º 4
0
def main():
    data = load_data.load('data1.txt')

    pos_values = data[(data[:, 2] == 1)]
    neg_values = data[(data[:, 2] == 0)]

    plot_data.plot(pos_values[:, 0], pos_values[:, 1], 'score1', 'score2', {
        'fmt': 'bx',
        'markersize': 5
    })

    plot_data.plot(neg_values[:, 0], neg_values[:, 1], 'score1', 'score2', {
        'fmt': 'yo',
        'markersize': 5,
        'show': True
    })
Ejemplo n.º 5
0
def main():
    x, y, origin_x = load_data.load_and_process('data1.txt')
    alpha = 0.003
    iterations = 1000000
    theta, j_list = gradient_descent(x, y, alpha, iterations)
    print(theta)

    iteration_array = range(iterations)
    plot_data.plot(iteration_array, j_list, 'iteration', "lost", {
        'fmt': 'b-',
        'title': 'Lost',
        'show': True
    })

    data = load_data.load('data1.txt')

    pos_values = data[(data[:, 2] == 1)]
    neg_values = data[(data[:, 2] == 0)]

    plot_data.plot(pos_values[:, 0], pos_values[:, 1], 'score1', 'score2', {
        'fmt': 'bx',
        'markersize': 5
    })

    plot_data.plot(neg_values[:, 0], neg_values[:, 1], 'score1', 'score2', {
        'fmt': 'yo',
        'markersize': 5,
        'show': False
    })

    score1 = np.linspace(25, 100)
    score2 = []
    for item in score1:
        score2.append(((0.5 - theta[0, 0]) - theta[1, 0] * item) / theta[2, 0])
    score2 = np.array(score2)

    plot_data.plot(score1, score2, 'score1', 'score2', {
        'fmt': 'r-',
        'show': True
    })
def main():
    fig, axes = plt.subplots(1, 3, sharey=True, figsize=(17, 5))
    data = load_data.load('data2.txt', dtype=np.float128)
    X = data[:, 0:2]
    X_map = feature_map.map(X)
    y = data[:, 2].reshape(-1, 1)
    initial_theta = np.zeros(X_map.shape[1])
    #C = 0
    #res = minimize(cost_function_reg, initial_theta, args=(C, X_map, y), method=None, jac=gradient_reg, options={'maxiter': 3000})
    #print(res)
    for i, C in enumerate([0, 1, 100]):
        # Optimize costFunctionReg
        res2 = minimize(cost_function_reg,
                        initial_theta,
                        args=(C, X_map, y),
                        method=None,
                        jac=gradient_reg,
                        options={'maxiter': 3000})
        accuracy = 100 * sum(predict(res2.x, X_map) == y.ravel()) / y.size
        plotData(data, 'Microchip Test 1', 'Microchip Test 2', 'y = 1',
                 'y = 0',
                 axes.flatten()[i])
        # Plot decisionboundary
        x1_min, x1_max = X[:, 0].min(), X[:, 0].max(),
        x2_min, x2_max = X[:, 1].min(), X[:, 1].max(),
        xx1, xx2 = np.meshgrid(np.linspace(x1_min, x1_max),
                               np.linspace(x2_min, x2_max))
        h = sigmoid.sigmoid(
            feature_map.map(np.c_[xx1.ravel(),
                                  xx2.ravel()]).dot(res2.x.reshape(-1, 1)))
        h = h.reshape(xx1.shape)
        axes.flatten()[i].contour(xx1, xx2, h, [0.5], linewidths=1, colors='g')
        axes.flatten()[i].set_title(
            'Train accuracy {}% with Lambda = {}'.format(
                np.round(accuracy, decimals=2), C))

    plt.show()
Ejemplo n.º 7
0
# python analysis.py basic.utt courses.utt lecturers.utt rooms.utt curricula.utt relation.utt unavailability.utt 0

params = sys.argv[1:]

datasets = [1, 5, 12, 13]
population_sizes = [100, 50, 35, 15, 10]
mutation_probabilities = [0.02, 0.05, 0.08, 0.15, 0.2]
compactness_initializations = [False]
no_runs = 4
runs = range(no_runs)

results = {}
for dataset in datasets:
    path = directory + 'dataset_' + str(dataset)

    data = load_data.load(params, index=dataset)

    num_lectures = []
    for k, v in data['courses'].iteritems():
        num_lectures.append(v['number_of_lectures'])
    max_lectures = max(num_lectures)

    horizontal_sizes = [3, 4]
    crossover_window_sizes = [(hs, max_lectures + vs) for hs, vs in zip(
        4 * [horizontal_sizes[0]] + 4 * [horizontal_sizes[1]], 2 *
        [-2, -1, 0, 1])]

    values_min = []

    for ps in population_sizes:
        for ci in compactness_initializations: