Esempio n. 1
0
def range_train():
    sample_sizes = [1e6]
    for size in sample_sizes:
        exp = Experiment("leagueoflegends", size, 75)
        model, losses, iterations = exp.regular_train()
        exp.predict(model, 1000, "s", True)

        plt.title("Losses for size " + str(size))

        plt.plot(iterations, losses)
        plt.xlabel("Iteration")
        plt.ylabel("Loss")

        if not os.path.exists("plots/" + str(size) + ".png"):
            plt.savefig("plots/" + str(size) + ".png")
        else:
            count = 1
            while os.path.exists("plots/" + str(size) + ".png"):
                count += 1
            plt.savefig("plots/" + str(size) + ".png")

        print("#" * 80)
        print("FINAL LOSS FOR SIZE ", size, losses[len(losses) - 1])
        print("#" * 80)

        plt.clf()
	def test_predict(self):
		# Test with dataset type: sklearn DataBunch
		experiment = Experiment('exp1', models=['rf', 'dt'], exp_type='classification')
		iris = load_iris()

		experiment.train(iris.data[:120], iris.target[:120])
		predictions = experiment.predict(iris.data[120:])
		actual = {
				'rf':
					[2, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], 
				'dt':
					[2, 1, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]}
		self.assertEqual( predictions, actual )

		# Test with dataset type: pandas DataFrame
		experiment = Experiment('exp1', models=['rf', 'dt'], exp_type='classification')
		iris_df = load_iris(as_frame=True).frame
		X = iris_df.loc[:, iris_df.columns != 'target']
		y = iris_df['target']

		experiment.train(X.iloc[:120], y.iloc[:120])
		predictions = experiment.predict(X.iloc[120:])
		actual = {
				'rf':
					[2, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], 
				'dt':
					[2, 1, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]}
		self.assertEqual( predictions, actual )
Esempio n. 3
0
def custom():
    filename = "../kelvin"
    exp = Experiment(subreddit=None,
                     sample_size=0,
                     percentile=0,
                     custom=True,
                     custom_file=filename)
    model, losses, iterations = exp.regular_train(epochs=5)
    exp.predict(model, 100, "s", False)
Esempio n. 4
0
def single_complete_train():
    exp = Experiment("leagueoflegends", None, 90)
    model, losses, iterations = exp.regular_train(epochs=1)
    exp.predict(model, 1000, "s", True)

    plt.title("Losses for size " + str(None))

    plt.plot(iterations, losses)
    plt.xlabel("Iteration")
    plt.ylabel("Loss")