<s> '''<STR_LIT>''' <EOL> import datetime as dt <EOL> '''<STR_LIT>''' <EOL> import numpy as np <EOL> import pandas as pand <EOL> import matplotlib . pyplot as plt <EOL> '''<STR_LIT>''' <EOL> from QSTK . qstkutil import DataAccess as da <EOL> from QSTK . qstkutil import qsdateutil as du <EOL> from QSTK . qstkfeat . features import featMA , featRSI , featDrawDown , featRunUp , featVolumeDelta , featAroon <EOL> from QSTK . qstkfeat . classes import class_fut_ret <EOL> import QSTK . qstkfeat . featutil as ftu <EOL> import sys <EOL> MAX_ITERATIONS = <NUM_LIT> <EOL> def learnerTest ( naTrain , naTest ) : <EOL> cLearn = ftu . createKnnLearner ( naTrain , lKnn = <NUM_LIT:5> ) <EOL> Ypredicted = cLearn . query ( naTest [ : , : - <NUM_LIT:1> ] ) <EOL> Y = naTest [ : , - <NUM_LIT:1> ] <EOL> corrcoef = np . corrcoef ( Y , Ypredicted ) [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> return corrcoef <EOL> def nextBestFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , lRemainingFeatures , classLabelIndex ) : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> bestFeature = - <NUM_LIT:1> <EOL> bestFeatureCorrCoef = <NUM_LIT:0> <EOL> for x in lRemainingFeatures : <EOL> lCurrentFeatureSet = [ x ] + lSelectedFeatures + [ classLabelIndex ] <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCurrentFeatureSet ) ) <EOL> currentTrain = naFeatTrain [ : , lCurrentFeatureSet ] <EOL> currentTest = naFeatTest [ : , lCurrentFeatureSet ] <EOL> currentCorrCoef = learnerTest ( currentTrain , currentTest ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( currentCorrCoef ) + '<STR_LIT:\n>' ) <EOL> if bestFeature == - <NUM_LIT:1> or bestFeatureCorrCoef < currentCorrCoef : <EOL> bestFeature = x <EOL> bestFeatureCorrCoef = currentCorrCoef <EOL> sys . stdout . write ( '<STR_LIT>' + str ( bestFeature ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( bestFeatureCorrCoef ) + '<STR_LIT>' ) <EOL> return { '<STR_LIT>' : bestFeature , '<STR_LIT>' : bestFeatureCorrCoef } <EOL> def nextWorstFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , classLabelIndex ) : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> if len ( lSelectedFeatures ) == <NUM_LIT:1> : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures [ <NUM_LIT:0> ] ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( - <NUM_LIT> ) + '<STR_LIT>' ) <EOL> return { '<STR_LIT>' : lSelectedFeatures [ <NUM_LIT:0> ] , '<STR_LIT>' : - <NUM_LIT> } <EOL> worstFeature = - <NUM_LIT:1> <EOL> worstFeatureCorrCoef = <NUM_LIT:0> <EOL> for x in lSelectedFeatures : <EOL> lSelectedFeaturesCopy = lSelectedFeatures [ : ] <EOL> lSelectedFeaturesCopy . remove ( x ) ; <EOL> lCurrentFeatureSet = lSelectedFeaturesCopy + [ classLabelIndex ] <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCurrentFeatureSet ) ) <EOL> currentTrain = naFeatTrain [ : , lCurrentFeatureSet ] <EOL> currentTest = naFeatTest [ : , lCurrentFeatureSet ] <EOL> currentCorrCoef = learnerTest ( currentTrain , currentTest ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( currentCorrCoef ) + '<STR_LIT:\n>' ) <EOL> if worstFeature == - <NUM_LIT:1> or worstFeatureCorrCoef < currentCorrCoef : <EOL> worstFeature = x <EOL> worstFeatureCorrCoef = currentCorrCoef <EOL> sys . stdout . write ( '<STR_LIT>' + str ( worstFeature ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( worstFeatureCorrCoef ) + '<STR_LIT>' ) <EOL> return { '<STR_LIT>' : worstFeature , '<STR_LIT>' : worstFeatureCorrCoef } <EOL> def sequentialForwardSelection ( naFeatTrain , naFeatTest , lFeatures , classLabelIndex ) : <EOL> lSelectedFeatures = list ( ) <EOL> lRemainingFeatures = lFeatures [ : ] <EOL> lCorrCoef = list ( ) ; <EOL> while len ( lRemainingFeatures ) > <NUM_LIT:0> : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lRemainingFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCorrCoef ) + '<STR_LIT:\n>' ) <EOL> retValue = nextBestFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , lRemainingFeatures , classLabelIndex ) <EOL> lSelectedFeatures . append ( retValue [ '<STR_LIT>' ] ) <EOL> lRemainingFeatures . remove ( retValue [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue [ '<STR_LIT>' ] ) <EOL> maxlCorrCoef = max ( lCorrCoef ) <EOL> maxlCorrCoefIndex = lCorrCoef . index ( maxlCorrCoef ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures [ <NUM_LIT:0> : maxlCorrCoefIndex + <NUM_LIT:1> ] + [ classLabelIndex ] ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( maxlCorrCoef ) ) <EOL> return maxlCorrCoef <EOL> def sequentialBackwardSelection ( naFeatTrain , naFeatTest , lFeatures , classLabelIndex ) : <EOL> lSelectedFeatures = lFeatures [ : ] <EOL> lCorrCoef = list ( ) <EOL> lRemovedFeatures = list ( ) <EOL> while len ( lSelectedFeatures ) > <NUM_LIT:0> : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lRemovedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCorrCoef ) + '<STR_LIT:\n>' ) <EOL> retValue = nextWorstFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , classLabelIndex ) <EOL> lSelectedFeatures . remove ( retValue [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue [ '<STR_LIT>' ] ) <EOL> lRemovedFeatures . append ( retValue [ '<STR_LIT>' ] ) <EOL> maxlCorrCoef = max ( lCorrCoef ) <EOL> maxlCorrCoefIndex = lCorrCoef . index ( maxlCorrCoef ) <EOL> lBestSet = list ( set ( lFeatures ) - set ( lRemovedFeatures [ <NUM_LIT:0> : maxlCorrCoefIndex + <NUM_LIT:1> ] ) ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lBestSet + [ classLabelIndex ] ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( maxlCorrCoef ) ) <EOL> return maxlCorrCoef <EOL> def sequentialFloatingForwardSelection ( naFeatTrain , naFeatTest , lFeatures , classLabelIndex ) : <EOL> global MAX_ITERATIONS <EOL> lSelectedFeatures = list ( ) <EOL> lRemainingFeatures = lFeatures [ : ] <EOL> lCorrCoef = list ( ) <EOL> lSeenStates = list ( ) <EOL> while len ( lRemainingFeatures ) > <NUM_LIT:0> : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lRemainingFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCorrCoef ) + '<STR_LIT:\n>' ) <EOL> retValue = nextBestFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , lRemainingFeatures , classLabelIndex ) <EOL> lSelectedFeatures . append ( retValue [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . remove ( retValue [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue [ '<STR_LIT>' ] ) <EOL> while True : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lRemainingFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCorrCoef ) + '<STR_LIT:\n>' ) <EOL> retValue2 = nextWorstFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , classLabelIndex ) <EOL> if lCorrCoef [ - <NUM_LIT:1> ] < retValue2 [ '<STR_LIT>' ] : <EOL> newState = set ( lSelectedFeatures ) <EOL> newState . remove ( retValue2 [ '<STR_LIT>' ] ) <EOL> if newState in lSeenStates : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> lSelectedFeatures . remove ( retValue2 [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . append ( retValue2 [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue2 [ '<STR_LIT>' ] ) <EOL> else : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> if len ( lSeenStates ) >= MAX_ITERATIONS : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( len ( lSeenStates ) ) + '<STR_LIT>' ) <EOL> break <EOL> maxlCorrCoef = max ( lCorrCoef ) <EOL> maxlCorrCoefIndex = lCorrCoef . index ( maxlCorrCoef ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( list ( lSeenStates [ maxlCorrCoefIndex ] ) + [ classLabelIndex ] ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( maxlCorrCoef ) ) <EOL> return maxlCorrCoef <EOL> def sequentialFloatingBackwardSelection ( naFeatTrain , naFeatTest , lFeatures , classLabelIndex ) : <EOL> global MAX_ITERATIONS <EOL> lSelectedFeatures = lFeatures [ : ] <EOL> lRemainingFeatures = list ( ) <EOL> lCorrCoef = list ( ) <EOL> lSeenStates = list ( ) <EOL> while len ( lSelectedFeatures ) > <NUM_LIT:0> : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lRemainingFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCorrCoef ) + '<STR_LIT:\n>' ) <EOL> retValue = nextWorstFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , classLabelIndex ) <EOL> lSelectedFeatures . remove ( retValue [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . append ( retValue [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue [ '<STR_LIT>' ] ) <EOL> while True : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lRemainingFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCorrCoef ) + '<STR_LIT:\n>' ) <EOL> retValue2 = nextBestFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , lRemainingFeatures , classLabelIndex ) <EOL> if lCorrCoef [ - <NUM_LIT:1> ] < retValue2 [ '<STR_LIT>' ] : <EOL> newState = set ( lSelectedFeatures ) <EOL> newState . add ( retValue2 [ '<STR_LIT>' ] ) <EOL> if newState in lSeenStates : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> lSelectedFeatures . append ( retValue2 [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . remove ( retValue2 [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue2 [ '<STR_LIT>' ] ) <EOL> else : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> if len ( lSeenStates ) >= MAX_ITERATIONS : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( len ( lSeenStates ) ) + '<STR_LIT>' ) <EOL> break <EOL> maxlCorrCoef = max ( lCorrCoef ) <EOL> maxlCorrCoefIndex = lCorrCoef . index ( maxlCorrCoef ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( list ( lSeenStates [ maxlCorrCoefIndex ] ) + [ classLabelIndex ] ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( maxlCorrCoef ) ) <EOL> return maxlCorrCoef <EOL> def sequentialFloatingForwardSelectionNew ( naFeatTrain , naFeatTest , lFeatures , classLabelIndex ) : <EOL> global MAX_ITERATIONS <EOL> lSelectedFeatures = list ( ) <EOL> lRemainingFeatures = lFeatures [ : ] <EOL> lCorrCoef = list ( ) <EOL> lSeenStates = list ( ) <EOL> retValue = <NUM_LIT:0> <EOL> while len ( lRemainingFeatures ) > <NUM_LIT:0> : <EOL> change = False <EOL> while True : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lRemainingFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCorrCoef ) + '<STR_LIT:\n>' ) <EOL> retValue = nextBestFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , lRemainingFeatures , classLabelIndex ) <EOL> if len ( lCorrCoef ) == <NUM_LIT:0> or lCorrCoef [ - <NUM_LIT:1> ] < retValue [ '<STR_LIT>' ] : <EOL> newState = set ( lSelectedFeatures ) <EOL> newState . add ( retValue [ '<STR_LIT>' ] ) <EOL> if newState in lSeenStates : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> lSelectedFeatures . append ( retValue [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . remove ( retValue [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue [ '<STR_LIT>' ] ) <EOL> else : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> while True : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lRemainingFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCorrCoef ) + '<STR_LIT:\n>' ) <EOL> retValue2 = nextWorstFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , classLabelIndex ) <EOL> if lCorrCoef [ - <NUM_LIT:1> ] < retValue2 [ '<STR_LIT>' ] : <EOL> newState = set ( lSelectedFeatures ) <EOL> newState . remove ( retValue2 [ '<STR_LIT>' ] ) <EOL> if newState in lSeenStates : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> lSelectedFeatures . remove ( retValue2 [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . append ( retValue2 [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue2 [ '<STR_LIT>' ] ) <EOL> change = True <EOL> else : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> if not change : <EOL> lSelectedFeatures . append ( retValue [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . remove ( retValue [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue [ '<STR_LIT>' ] ) <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> if len ( lSeenStates ) >= MAX_ITERATIONS : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( len ( lSeenStates ) ) + '<STR_LIT>' ) <EOL> break <EOL> maxlCorrCoef = max ( lCorrCoef ) <EOL> maxlCorrCoefIndex = lCorrCoef . index ( maxlCorrCoef ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( list ( lSeenStates [ maxlCorrCoefIndex ] ) + [ classLabelIndex ] ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( maxlCorrCoef ) ) <EOL> return maxlCorrCoef <EOL> def sequentialFloatingBackwardSelectionNew ( naFeatTrain , naFeatTest , lFeatures , classLabelIndex ) : <EOL> global MAX_ITERATIONS <EOL> lSelectedFeatures = lFeatures [ : ] <EOL> lRemainingFeatures = list ( ) <EOL> lCorrCoef = list ( ) <EOL> lSeenStates = list ( ) <EOL> retValue = <NUM_LIT:0> <EOL> while len ( lSelectedFeatures ) > <NUM_LIT:0> : <EOL> change = False <EOL> while True : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lRemainingFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCorrCoef ) + '<STR_LIT:\n>' ) <EOL> retValue = nextWorstFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , classLabelIndex ) <EOL> if len ( lCorrCoef ) == <NUM_LIT:0> or lCorrCoef [ - <NUM_LIT:1> ] < retValue [ '<STR_LIT>' ] : <EOL> newState = set ( lSelectedFeatures ) <EOL> newState . remove ( retValue [ '<STR_LIT>' ] ) <EOL> if newState in lSeenStates : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> lSelectedFeatures . remove ( retValue [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . append ( retValue [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue [ '<STR_LIT>' ] ) <EOL> else : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> while True : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lRemainingFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCorrCoef ) + '<STR_LIT:\n>' ) <EOL> retValue2 = nextBestFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , lRemainingFeatures , classLabelIndex ) <EOL> if lCorrCoef [ - <NUM_LIT:1> ] < retValue2 [ '<STR_LIT>' ] : <EOL> newState = set ( lSelectedFeatures ) <EOL> newState . add ( retValue2 [ '<STR_LIT>' ] ) <EOL> if newState in lSeenStates : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> lSelectedFeatures . append ( retValue2 [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . remove ( retValue2 [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue2 [ '<STR_LIT>' ] ) <EOL> change = True <EOL> else : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> if not change : <EOL> lSelectedFeatures . remove ( retValue [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . append ( retValue [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue [ '<STR_LIT>' ] ) <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> if len ( lSeenStates ) >= MAX_ITERATIONS : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( len ( lSeenStates ) ) + '<STR_LIT>' ) <EOL> break <EOL> maxlCorrCoef = max ( lCorrCoef ) <EOL> maxlCorrCoefIndex = lCorrCoef . index ( maxlCorrCoef ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( list ( lSeenStates [ maxlCorrCoefIndex ] ) + [ classLabelIndex ] ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( maxlCorrCoef ) ) <EOL> return maxlCorrCoef <EOL> def sequentialFloatingForwardSelectionNew_Max ( naFeatTrain , naFeatTest , lFeatures , classLabelIndex ) : <EOL> global MAX_ITERATIONS <EOL> lSelectedFeatures = list ( ) <EOL> lRemainingFeatures = lFeatures [ : ] <EOL> lCorrCoef = list ( ) <EOL> lSeenStates = list ( ) <EOL> maxCorrCoef = - <NUM_LIT:100> <EOL> retValue = <NUM_LIT:0> <EOL> while len ( lRemainingFeatures ) > <NUM_LIT:0> : <EOL> change = False <EOL> while True : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lRemainingFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCorrCoef ) + '<STR_LIT:\n>' ) <EOL> retValue = nextBestFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , lRemainingFeatures , classLabelIndex ) <EOL> if len ( lCorrCoef ) == <NUM_LIT:0> or maxCorrCoef < retValue [ '<STR_LIT>' ] : <EOL> newState = set ( lSelectedFeatures ) <EOL> newState . add ( retValue [ '<STR_LIT>' ] ) <EOL> if newState in lSeenStates : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> lSelectedFeatures . append ( retValue [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . remove ( retValue [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue [ '<STR_LIT>' ] ) <EOL> maxCorrCoef = max ( maxCorrCoef , retValue [ '<STR_LIT>' ] ) <EOL> else : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> while True : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lRemainingFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCorrCoef ) + '<STR_LIT:\n>' ) <EOL> retValue2 = nextWorstFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , classLabelIndex ) <EOL> if maxCorrCoef < retValue2 [ '<STR_LIT>' ] : <EOL> newState = set ( lSelectedFeatures ) <EOL> newState . remove ( retValue2 [ '<STR_LIT>' ] ) <EOL> if newState in lSeenStates : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> lSelectedFeatures . remove ( retValue2 [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . append ( retValue2 [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue2 [ '<STR_LIT>' ] ) <EOL> maxCorrCoef = max ( maxCorrCoef , retValue2 [ '<STR_LIT>' ] ) <EOL> change = True <EOL> else : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> if not change : <EOL> lSelectedFeatures . append ( retValue [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . remove ( retValue [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue [ '<STR_LIT>' ] ) <EOL> maxCorrCoef = max ( maxCorrCoef , retValue [ '<STR_LIT>' ] ) <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> if len ( lSeenStates ) >= MAX_ITERATIONS : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( len ( lSeenStates ) ) + '<STR_LIT>' ) <EOL> break <EOL> maxlCorrCoef = max ( lCorrCoef ) <EOL> maxlCorrCoefIndex = lCorrCoef . index ( maxlCorrCoef ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( list ( lSeenStates [ maxlCorrCoefIndex ] ) + [ classLabelIndex ] ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( maxlCorrCoef ) ) <EOL> return maxlCorrCoef <EOL> def sequentialFloatingBackwardSelectionNew_Max ( naFeatTrain , naFeatTest , lFeatures , classLabelIndex ) : <EOL> global MAX_ITERATIONS <EOL> lSelectedFeatures = lFeatures [ : ] <EOL> lRemainingFeatures = list ( ) <EOL> lCorrCoef = list ( ) <EOL> lSeenStates = list ( ) <EOL> maxCorrCoef = - <NUM_LIT:100> <EOL> retValue = <NUM_LIT:0> <EOL> while len ( lSelectedFeatures ) > <NUM_LIT:0> : <EOL> change = False <EOL> while True : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lRemainingFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCorrCoef ) + '<STR_LIT:\n>' ) <EOL> retValue = nextWorstFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , classLabelIndex ) <EOL> if len ( lCorrCoef ) == <NUM_LIT:0> or maxCorrCoef < retValue [ '<STR_LIT>' ] : <EOL> newState = set ( lSelectedFeatures ) <EOL> newState . remove ( retValue [ '<STR_LIT>' ] ) <EOL> if newState in lSeenStates : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> lSelectedFeatures . remove ( retValue [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . append ( retValue [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue [ '<STR_LIT>' ] ) <EOL> maxCorrCoef = max ( maxCorrCoef , retValue [ '<STR_LIT>' ] ) <EOL> else : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> while True : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lSelectedFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lRemainingFeatures ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( lCorrCoef ) + '<STR_LIT:\n>' ) <EOL> retValue2 = nextBestFeature ( naFeatTrain , naFeatTest , lSelectedFeatures , lRemainingFeatures , classLabelIndex ) <EOL> if maxCorrCoef < retValue2 [ '<STR_LIT>' ] : <EOL> newState = set ( lSelectedFeatures ) <EOL> newState . add ( retValue2 [ '<STR_LIT>' ] ) <EOL> if newState in lSeenStates : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> lSelectedFeatures . append ( retValue2 [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . remove ( retValue2 [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue2 [ '<STR_LIT>' ] ) <EOL> maxCorrCoef = max ( maxCorrCoef , retValue2 [ '<STR_LIT>' ] ) <EOL> change = True <EOL> else : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> if not change : <EOL> lSelectedFeatures . remove ( retValue [ '<STR_LIT>' ] ) <EOL> lSeenStates . append ( set ( lSelectedFeatures ) ) <EOL> lRemainingFeatures . append ( retValue [ '<STR_LIT>' ] ) <EOL> lCorrCoef . append ( retValue [ '<STR_LIT>' ] ) <EOL> maxCorrCoef = max ( maxCorrCoef , retValue [ '<STR_LIT>' ] ) <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> if len ( lSeenStates ) >= MAX_ITERATIONS : <EOL> sys . stdout . write ( '<STR_LIT>' + str ( len ( lSeenStates ) ) + '<STR_LIT>' ) <EOL> break <EOL> maxlCorrCoef = max ( lCorrCoef ) <EOL> maxlCorrCoefIndex = lCorrCoef . index ( maxlCorrCoef ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( list ( lSeenStates [ maxlCorrCoefIndex ] ) + [ classLabelIndex ] ) + '<STR_LIT:\n>' ) <EOL> sys . stdout . write ( '<STR_LIT>' + str ( maxlCorrCoef ) ) <EOL> return maxlCorrCoef </s>
