def learnerTest( naTrain, naTest ):
    ''' 
    @summary: Takes testing and training data and computes average error over the test set
              This is compared to a baseline guess which is just the average of the training set
    '''
    llRange = range(5,51,5)
    
    lfRes = []
    for lK in llRange:
        cLearn = ftu.createKnnLearner( naTrain, lKnn=lK )
        fError = 0.0

        naResult = cLearn.query( naTest[:,:-1] )
        naError = abs( naResult - naTest[:,-1] )
        lfRes.append( np.average(naError) )
    
    ''' Generate error of 'dumb' case, just assume average returns every time '''
    naGuess = np.ones( naTest.shape[0] ) * np.average( naTrain[:,-1] )
    lfGuess = [ np.average( abs(naGuess - naTest[:,-1]) ) ] * len(lfRes)
    
    fAvgRets = np.average(naTest[:,-1])
    
    plt.clf()
    plt.plot( llRange, lfRes )
    plt.plot( llRange, lfGuess )
    plt.title( 'Average error on average returns of %.04lf'%fAvgRets )
    plt.legend( ('Learner Predict', 'Average Return Predict') )
    plt.xlabel('K value')
    plt.ylabel('Error')
    #plt.show()
    plt.savefig( 'FeatureTest.png', format='png' )
Example #2
0
def learnerTest(naTrain, naTest):
    ''' 
    @summary: Takes testing and training data and computes average error over the test set
              This is compared to a baseline guess which is just the average of the training set
    '''
    llRange = range(5, 51, 5)

    lfRes = []
    for lK in llRange:
        cLearn = ftu.createKnnLearner(naTrain, lKnn=lK, leafsize=100)
        fError = 0.0

        naResult = cLearn.query(naTest[:, :-1])
        naError = abs(naResult - naTest[:, -1])
        lfRes.append(np.average(naError))
    ''' Generate error of 'dumb' case, just assume average returns every time '''
    naGuess = np.ones(naTest.shape[0]) * np.average(naTrain[:, -1])
    lfGuess = [np.average(abs(naGuess - naTest[:, -1]))] * len(lfRes)

    fAvgRets = np.average(naTest[:, -1])

    plt.clf()
    plt.plot(llRange, lfRes)
    plt.plot(llRange, lfGuess)
    plt.title('Average error on average returns of %.04lf' % fAvgRets)
    plt.legend(('Learner Predict', 'Average Return Predict'))
    plt.xlabel('K value')
    plt.ylabel('Error')
    plt.show()
    plt.savefig('FeatureTest.png', format='png')
Example #3
0
def learnerTest( naTrain, naTest ):
    
    kdtlearner = ftu.createKnnLearner( naTrain, 5 )

    naResult = kdtlearner.query( naTest[:,:-1] )

    correlation = np.corrcoef(naResult,naTest[:,-1])
    return correlation
Example #4
0
def learnerTest( naTrain, naTest ):
	#create the learner with the train set with K=5
	cLearn = ftu.createKnnLearner( naTrain, lKnn=5 )
	#get the Y values predicted by the learner
	Ypredicted = cLearn.query( naTest[:,:-1] )
	#get the actual Y values
	Y = naTest[:,-1]
	#calculate the correlation coefficient
	corrcoef = np.corrcoef(Y,Ypredicted)[0][1]
	#return the corrcoef
	return corrcoef	
Example #5
0
def learnerTest(naTrain, naTest):
    #create the learner with the train set with K=5
    cLearn = ftu.createKnnLearner(naTrain, lKnn=5)
    #get the Y values predicted by the learner
    Ypredicted = cLearn.query(naTest[:, :-1])
    #get the actual Y values
    Y = naTest[:, -1]
    #calculate the correlation coefficient
    corrcoef = np.corrcoef(Y, Ypredicted)[0][1]
    #return the corrcoef
    return corrcoef