Пример #1
0
def main():
	x = gam.getAdjMat('redwine.csv', False) ## getAdjMatrix1.getmatrix returns a tuple
	std = x[0]
	mean = x[1]
	matrix = x[2]
	thetas = np.array([1.10E-01,-1.80E-01,-1.30E-02,-6.59E-03,-9.09E-02,3.40E-02, -6.71E-02, -1.29E-01, -7.13E-02, 2.01E-01, 3.77E-01 ,-7.33E-02])
	predictedValuesT = predictValue('redwineTest.csv', thetas, False, std, mean, "predictedTestResult1.csv", False)
	print reportError(predictedValuesT, 'redwineTestResult.csv')
	array = []
	for i in range(60):
		alpha = random.uniform(0.0001, 0.01)
		gamma = random.uniform(0.00000001, 0.00001)
		results = regressionAndTestError('whitewineTraining.csv', 'whiteWineVal.csv', 
		'whitewineValResult.csv', 'whitewineTest.csv', 'whitewineTestResult.csv', alpha, 
		0.0001, gamma, False, False, False)
		array.append(results)
		print "\n\nLoop ", i 
		np.savetxt("RegressionResults.csv", np.asarray(array), delimiter=",")
Пример #2
0
def regressionAndTestError(trainingSetFile, ValidationSetFile, ValidationSetResultFile, 
	testSetFile, testSetAnswerFile, alpha, epsilon, gamma, quadratic, ridge, rounded):
	x = gam.getAdjMat(trainingSetFile, quadratic) ## getAdjMatrix1.getmatrix returns a tuple
	std = x[0]
	mean = x[1]
	matrix = x[2]
	thetas = stochasticRegression(matrix, alpha, gamma, epsilon, ridge)
	print "...\nPredicting Validation Set..."
	predictedValues = predictValue(ValidationSetFile, thetas, quadratic, std, mean, "predictedValResult.csv", rounded)
	error = reportError(predictedValues, ValidationSetResultFile)
	print "The average squared error for the Validation Set is ", error
	print "...\nPredicting test Set..."
	predictedValuesT = predictValue(testSetFile, thetas, quadratic, std, mean, "predictedTestResult.csv", rounded)
	errorT = reportError(predictedValuesT, testSetAnswerFile)
	print "The average squared error status of this model is ", errorT
	thetas = np.insert(thetas, thetas.shape[0], alpha)
	thetas = np.insert(thetas, thetas.shape[0], gamma)
	thetas = np.insert(thetas, thetas.shape[0], error)
	thetas = np.insert(thetas, thetas.shape[0], errorT)

	return thetas