Exemplo n.º 1
0
def start():
    featuresList=[]
    labelsList=[]
    featuresList, labelsList= loadFile("output.txt")

    print 'Normalizing array...'

    normalizearray(featuresList)
   
 
    alldata = ClassificationDataSet( len(featuresList[0]), 1, nb_classes=8, class_labels=['ffi_brainmatter','ffi_neuron','ffi_vacuole','ffi_astrocyte', 'wt_brainmatter', 'wt_neuron', 'wt_vacuole', 'wt_astrocyte'] )
    for i in range(len(labelsList)):
         alldata.appendLinked(featuresList[i], labelsList[i])
          
         
    #print 'All data: ', alldata
    #print 'Statisticcs: ', alldata.calculateStatistics()
    
    newK=fSel.getTreeFeatures(featuresList, labelsList);
    newK=newK.shape[1]
    print "K= ", newK
    reducedFeatures= fSel.getBestK(featuresList,labelsList, 'f_classif', newK)
    reducedData=ClassificationDataSet( len(reducedFeatures[0]), 1, nb_classes=8, class_labels=['ffi_brainmatter','ffi_neuron','ffi_vacuole','ffi_astrocyte', 'wt_brainmatter', 'wt_neuron', 'wt_vacuole', 'wt_astrocyte'] )
    
    #prep reducedData object with reduced feature list
    for i in range(len(labelsList)):
        reducedData.appendLinked(reducedFeatures[i], labelsList[i])
    
    
    print 'Splitting test and training data...'
    tstdata, trndata = alldata.splitWithProportion( 0.30 )
    reducedTestData, reducedTrainData=reducedData.splitWithProportion(0.3)
    
    print 'Number of training and test patterns: ', len(trndata), len(tstdata)
    
    
    trndata._convertToOneOfMany(bounds=[0,1])
    tstdata._convertToOneOfMany(bounds=[0,1])  
    
    reducedTestData._convertToOneOfMany(bounds=[0,1])
    reducedTrainData._convertToOneOfMany(bounds=[0,1])
    
    
    #print "Number of training patterns: ", len(trndata)
    print "Input and output dimensions: ", trndata.indim, trndata.outdim
    #print "Sample (input, target, class):"
    #print trndata['input'][0], trndata['target'][0], trndata['class'][0]
    #print trndata['input'][1], trndata['target'][1], trndata['class'][1]

    
    buildFNN(tstdata, trndata)
    
    print "___________________________________________FEATURE REDUCTION________________________________________________"
    buildFNN(reducedTestData, reducedTrainData)
def start(fName, K=None):
    '''
    inputFile, number of features to be selected, default is none
    '''
    X,y= readFile.loadFile(fName)
    getMask(X, y, K)