Пример #1
0
def main(_):
    """High level pipeline.

    This scripts performs the training and evaling and testing stages for
    semi-supervised learning using kMeans algorithm.
    """
    # Load dataset.
    _, unlabeled_data = io_tools.read_dataset('data/simple_test.csv')
    n_dims = unlabeled_data.shape[1]

    # Initialize model.
    model = GaussianMixtureModel(n_dims,
                                 n_components=FLAGS.n_components,
                                 max_iter=FLAGS.max_iter)

    # Unsupervised training.
    # model.fit(unlabeled_data)

    # Supervised training.
    train_label, train_data = io_tools.read_dataset('data/simple_test.csv')
    model.supervised_fit(train_data, train_label)

    # Eval model.
    eval_label, eval_data = io_tools.read_dataset('data/simple_test.csv')
    y_hat_eval = model.supervised_predict(eval_data)

    acc = np.sum(y_hat_eval == eval_label) / (1. * eval_data.shape[0])
    print("Accuracy: %s" % acc)
Пример #2
0
    def setUp(self):
        n_dims = 2
        unlabeled_data = np.random.normal(-1, 0.1, [100, n_dims])
        unlabeled_data = np.concatenate(
            (unlabeled_data, np.random.normal(1, 0.1, [50, n_dims])))

        self.n_dims = 2
        self.n_components = 2
        self.max_iter = 1
        self.model = GaussianMixtureModel(self.n_dims,
                                          n_components=self.n_components,
                                          max_iter=self.max_iter)