def test(trd, trc, ted, tec):
        X1, Y1 = bootstrap_data(trd, trc, round(len(trd) * .5))
        X2, Y2 = bootstrap_data(trd, trc, round(len(trd) * .5))

        base = bases[np.random.randint(len(bases))]
        gd = GradBoost(base, 10, X1, Y1)

        print('gd', '\n')
        print(gd, '\n')

        err = gd.mse(ted, tec)
        print('gd.mse =', err, '\n')

        print('gd.predict(ted)')
        print(gd.predict(ted))

        print('gd.get_n()')
        print(gd.get_n())

        gd.train(base, 6, X2, Y2)

        print('gd.get_n()')
        print(gd.get_n())

        err = gd.mse(ted, tec)
        print('gd.mse =', err, '\n')

        print('gd.predict(ted)')
        print(gd.predict(ted))

        return err
Exemple #2
0
    def test(trd, trc, ted, tec):
        X1, Y1 = bootstrap_data(trd, trc, round(len(trd) * .5))
        X2, Y2 = bootstrap_data(trd, trc, round(len(trd) * .5))

        base = bases[np.random.randint(len(bases))]

        ab = AdaBoost(base, 10, X1, Y1)

        print('ab', '\n')
        print(ab)

        err = ab.err(ted, tec)
        print('err =', err)

        print('ab.n_ensemble')
        print(ab.n_ensemble)

        ab.train(base, 7, X2, Y2)

        print('ab.n_ensemble')
        print(ab.n_ensemble)

        err = ab.err(ted, tec)
        print('err =', err)

        return err
	def test(trd, trc, ted, tec):
		X1,Y1 = bootstrap_data(trd, trc, round(len(trd) * .5))
		X2,Y2 = bootstrap_data(trd, trc, round(len(trd) * .5))

		base = bases[np.random.randint(len(bases))]
		gd = GradBoost(base, 10, X1, Y1)

		print('gd', '\n')
		print(gd, '\n')

		err = gd.mse(ted, tec)
		print('gd.mse =', err, '\n')

		print('gd.predict(ted)')
		print(gd.predict(ted))

		print('gd.get_n()')
		print(gd.get_n())

		gd.train(base, 6, X2, Y2)

		print('gd.get_n()')
		print(gd.get_n())

		err = gd.mse(ted, tec)
		print('gd.mse =', err, '\n')

		print('gd.predict(ted)')
		print(gd.predict(ted))

		return err

################################################################################
################################################################################
################################################################################

################################################################################
## MAIN ########################################################################
################################################################################

if __name__ == '__main__':

    data, predictions = load_data_from_csv('../data/regressor-data.csv', -1,
                                           float)
    data, predictions = arr(data), arr(predictions)
    data, predictions = bootstrap_data(data, predictions, 1000)

    # bases = [LinearRegress, LogisticRegress, KNNRegress, TreeRegress]
    bases = [KNNRegress]

    def test(trd, trc, ted, tec):
        X1, Y1 = bootstrap_data(trd, trc, round(len(trd) * .5))
        X2, Y2 = bootstrap_data(trd, trc, round(len(trd) * .5))

        base = bases[np.random.randint(len(bases))]
        gd = GradBoost(base, 10, X1, Y1)

        print('gd', '\n')
        print(gd, '\n')

        err = gd.mse(ted, tec)
Exemple #5
0
################################################################################
################################################################################
################################################################################


################################################################################
## MAIN ########################################################################
################################################################################


if __name__ == '__main__':

## RANDOM TESTING ##############################################################

	X,Y = load_data_from_csv('../data/binary.csv', 4, float)
	X,Y = bootstrap_data(X, Y, 1000)
	# X,mu,scale = rescale(X)
	Xtr,Xte,Ytr,Yte = split_data(X, Y, .8)
	
	nc = NNetClassify(Xtr, Ytr, [4,2,3,2], init='random', max_steps=5000, activation='htangent')
	print(nc.get_weights())
	print(nc)
	print(nc.predict(Xte))
	print(nc.predict_soft(Xte))
	print(nc.err(Xte, Yte))

## DETERMINISTIC TESTING #######################################################

#	data = [[float(val) for val in row[:-1]] for row in csv.reader(open('../data/classifier-data.csv'))]
#	trd = np.asarray(data[0:40] + data[50:90] + data[100:140])
#	ted = np.asarray(data[40:50] + data[90:100] + data[140:150])
################################################################################
################################################################################
################################################################################


################################################################################
## MAIN ########################################################################
################################################################################


if __name__ == '__main__':

	data,predictions = load_data_from_csv('../data/regressor-data.csv', -1, float)
	data,predictions = arr(data), arr(predictions)
	data,predictions = bootstrap_data(data, predictions, 1000)

	# bases = [LinearRegress, LogisticRegress, KNNRegress, TreeRegress]
	bases = [KNNRegress]

	def test(trd, trc, ted, tec):
		X1,Y1 = bootstrap_data(trd, trc, round(len(trd) * .5))
		X2,Y2 = bootstrap_data(trd, trc, round(len(trd) * .5))

		base = bases[np.random.randint(len(bases))]
		gd = GradBoost(base, 10, X1, Y1)

		print('gd', '\n')
		print(gd, '\n')

		err = gd.mse(ted, tec)