if __name__ == "__main__":
    
    source = 'linear'
    
    if source == 'temp':
        data = pd.read_csv('../dataset/simple/TempLinkoping2016.txt', sep="\t")

        time = np.atleast_2d(data["time"].values).T
        temp = np.atleast_2d(data["temp"].values).T
    
        X = standardize(time)        # Time. Fraction of the year [0, 1]
        y = temp[:, 0]  # Temperature. Reduce to one-dim
    
        X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
    
        model = LinearRegression(X_train, y_train).train()
        y_pred = model.evaluation(X_test, y_test, title="test")
        
    if source == 'linear':
        dataset = RegressionDataset(n_samples=500, n_features=1, n_targets=1, noise=5)
        X = dataset.datas
        y = dataset.labels
#        plt.scatter(X, y)
        
        X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

        model = LinearRegression(X_train, y_train, lr=0.001, n_iters=100).train()
        y_pred = model.evaluation(X_test, y_test, title='test')
           
Пример #2
0
        self.add(BatchNorm2d(256))
        self.add(Activation('softmax'))


if __name__ == "__main__":

    id = 'lenet5'

    if id == 'lenet5':

        dataset = DigitsDataset(norm=True, one_hot=True)
        datas = dataset.datas
        labels = dataset.labels
        # 分隔数据集
        train_x, test_x, train_y, test_y = train_test_split(dataset.datas,
                                                            dataset.labels,
                                                            test_size=0.3,
                                                            shuffle=True)
        #        test_x, val_x, test_y, val_y = train_test_split(test_x,
        #                                                        test_y,
        #                                                        test_size=0.3,
        #                                                        shuffle=True)
        train_x = train_x.reshape(-1, 1, 8, 8)
        test_x = test_x.reshape(-1, 1, 8, 8)
        #        val_x = val_x.reshape(-1, 1, 8, 8)

        optimizer = SGDM(lr=0.01, weight_decay=0.1, regularization_type='l2')

        loss_func = CrossEntropy()
        clf = LeNet5(train_x,
                     train_y,
                     loss=loss_func,
Пример #3
0
                  min_samples_split=3,
                  max_depth=5,
                  min_impurity_reduction=1e-7).train()
        gb.evaluation(x, y)
        gb.vis_boundary(plot_step=0.01)

    if source == '5class':
        dataset = MultiClassDataset(n_samples=500,
                                    centers=4,
                                    n_features=2,
                                    center_box=(-8, +8),
                                    cluster_std=0.8,
                                    one_hot=True)
        x = dataset.datas
        y = dataset.labels
        train_x, test_x, train_y, test_y = train_test_split(
            x, y, test_size=0.3)  # (n, 13) (n,)
        gb = GBDT(x,
                  y,
                  n_clfs=2,
                  learning_rate=0.5,
                  min_samples_split=3,
                  max_depth=5,
                  min_impurity_reduction=1e-7).train()
        acc1 = gb.evaluation(train_x, train_y)
        print('train acc = %f' % (acc1))

        acc2 = gb.evaluation(test_x, test_y)
        print('test acc = %f' % (acc2))

        gb.vis_boundary(plot_step=0.1)