Esempio n. 1
0
def get_point(ys):
    xs = range(len(ys))
    ys = ys['Adj. Close']

    result = (0, -99999)
    for i in xs[CHECK_PERIOD:-CHECK_PERIOD]:

        before_line = linear_regression.train(xs[i - CHECK_PERIOD:i],
                                              ys[i - CHECK_PERIOD:i])
        after_line = linear_regression.train(xs[i:i + CHECK_PERIOD],
                                             ys[i:i + CHECK_PERIOD])

        fracture = after_line[0]**2 / before_line[0]**2
        if fracture > result[1]:
            result = i, fracture, before_line, after_line

    if result[0]:
        return result
    else:
        return None
Esempio n. 2
0
            def train_function(x, y, model, window_state):
                if not model:
                    class Model:
                        w = np.zeros((x.shape[1] + 1, 1))
                        sum_error = 0
                        i = 0
                    model = Model()

                model.w = train(x, y, self.draw)
                self.w = model.w
                error = evaluate_error(x, y, model.w)
                if self.output:
                    print "Error: ", error

                model.sum_error += error
                model.i += 1
                return model
            def train_function(x, y, model, window_state):
                if not model:

                    class Model:
                        w = np.zeros((x.shape[1] + 1, 1))
                        sum_error = 0
                        i = 0

                    model = Model()

                model.w = train(x, y, self.draw)
                self.w = model.w
                error = evaluate_error(x, y, model.w)
                if self.output:
                    print "Error: ", error

                model.sum_error += error
                model.i += 1
                return model
def main():
    x = []
    valid = []
    test = []
    for i in xrange(2, 68, 5):
        print "Current training set size: ", i

        shutil.rmtree(TRAIN_DIR, ignore_errors=True)
        shutil.rmtree(TEST_DIR, ignore_errors=True)
        shutil.rmtree(VALIDATION_DIR, ignore_errors=True)

        split_data.split_data(i)

        theta = linear_regression.train()
        x.append(i)
        valid.append(linear_regression.validation(theta))
        test.append(linear_regression.eval(theta))
    plt.plot(x, valid)
    plt.plot(x, test)
    plt.ylabel('Accuracy')
    plt.xlabel('Training Set Size')
    plt.show()
import numpy as np
import linear_regression

# Import the dataset
X, Y = np.loadtxt("pizza.txt", skiprows=1, unpack=True)

# Train the system with a learning rate of 0.00001
w, b = linear_regression.train(X, Y, iterations=10000, lr=0.00001)
print("\nw=%.3f, b=%.3f" % (w, b))

# Predict the number of pizzas
print("Prediction: x=%d => y=%.2f" % (20, linear_regression.predict(20, w, b)))
Esempio n. 6
0
# !/usr/bin/python3

import my_dataset
import neural_network
import linear_regression
import os

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

if False:
    data = my_dataset.random_linear()
    linear_regression.train(data)

if False:
    train_dataset, test_normed_dataframe, test_labels_dataframe = my_dataset.auto_mpg(
    )
    neural_network.mpg_train(train_dataset, test_normed_dataframe,
                             test_labels_dataframe)

if False:
    (x_train,
     y_train), (x_test, y_test), input_shape, num_classes = my_dataset.mnist()
    neural_network.mnist_train(x_train, y_train, x_test, y_test, input_shape,
                               num_classes)

if True:
    x_batch = my_dataset.synthetic_batch(4)
    neural_network.resnet50_train(x_batch)