Example #1
0
 def setUp(self):
     (self.x_train,
      self.y_train), (self.x_test,
                      self.y_test) = tf.keras.datasets.mnist.load_data()
     self.x_train = np.array(self.x_train, dtype=float)
     self.x_test = np.array(self.x_test, dtype=float)
     self.x_train /= 255
     self.x_test /= 255
     self.x_train = self.x_train.reshape(784, -1)
     self.x_test = self.x_test.reshape(784, -1)
     self.y_train = one_hot_encode(self.y_train.reshape(1, -1))
     self.y_test = one_hot_encode(self.y_test.reshape(1, -1))
     self.x_mini_train = self.x_train[:, :1000].reshape(784, -1)
     self.y_mini_train = self.y_train[:, :1000]
     self.x_mini_valid = self.x_train[:, 1000:2000].reshape(784, -1)
     self.y_mini_valid = self.y_train[:, 1000:2000]
     return super().setUp()
Example #2
0
    def setUp(self):
        self.x, self.y = load_iris(return_X_y=True)
        self.x = preprocessing.scale(self.x).T
        self.y_encoded = one_hot_encode(self.y)
        self.softmax_model_no_regularization = SoftmaxRegression(
            self.x.shape[0], len(self.y_encoded))

        self.softmax_model_l1_regularization = SoftmaxRegression(
            self.x.shape[0],
            len(self.y_encoded),
            regularization="L1",
            reg_parameter=0.01)

        self.softmax_model_l2_regularization = SoftmaxRegression(
            self.x.shape[0],
            len(self.y_encoded),
            regularization="L2",
            reg_parameter=0.01)

        self.k_fold_obj = KFoldCrossValidation()
def create_spiral_dataset():
    """ Function creates a 2 dimensional spiral dataset, returning
    100 feature vectors and encoded and unencoded labels for those
    vectors.
    """
    num_points = 100  # number of points per class
    dimensions = 2  # dimensionality
    num_classes = 3  # number of classes
    x = np.zeros((num_points * num_classes,
                  dimensions))  # data matrix (each row = single example)
    y = np.zeros(num_points * num_classes, dtype="uint8")  # class labels
    for j in range(num_classes):
        ix = range(num_points * j, num_points * (j + 1))
        r = np.linspace(0.0, 1, num_points)  # radius
        t = np.linspace(
            j * 4, (j + 1) * 4,
            num_points) + np.random.randn(num_points) * 0.2  # theta
        x[ix] = np.c_[r * np.sin(t), r * np.cos(t)]
        y[ix] = j

    x = x.T
    not_encoded_y = y
    y = one_hot_encode(y.reshape(1, -1))
    return x, y, not_encoded_y