predict_svm/PredictSVM.py
def predict2(self):
        ''' Predict2 is an updated version which uses sklearn tools for svm instead of
        coding from scratch

        '''


        # make SVM_Scores output for animal
        try:
            os.mkdir(os.path.join(self.root_dir, self.animal_id, "SVM_Scores"))
        except:
            pass


        # find specific session if only 1 chosen
        self.get_sessions()

        #
        prefix1 = ''
        if self.lockout:
            prefix1 = '_lockout_'+str(self.lockout_window)+"sec"

        #
        prefix2 = ''
        if self.pca_flag:
            prefix2 = '_pca_'+str(self.pca_var)

        for s in range(len(self.sessions)):
            #
            fname_out = os.path.join(self.root_dir, self.animal_id,'SVM_Scores',
                                 'SVM_Scores_'+
                                 self.sessions[s]+
                                 self.code+
                                 prefix1+
                                 '_trial_ROItimeCourses_'+
                                 str(self.window)+'sec'+
                                 "_Xvalid"+str(self.xvalidation)+
                                 "_Slidewindow"+str(self.sliding_window)+
                                 '.npz'
                                 )

            if os.path.exists(fname_out) and self.overwrite==False:
                print ("   already computed, skipping ...")
                continue

            # grab trial and random data
            fname = os.path.join(self.root_dir, self.animal_id,'tif_files',
                                 self.sessions[s],
                                 self.sessions[s]+'_'+
                                 self.code+
                                 prefix1+
                                 '_trial_ROItimeCourses_'+
                                 str(self.window)+'sec'+
                                 prefix2+
                                 '.npy'
                                 )
            try:
                trial_courses_fixed = np.load(fname)
                trial_courses_random_fixed = np.load(fname.replace('trial','random'))
            except:
                print (" ....file not found, skippping ")
                continue

            if trial_courses_fixed.shape[0] < self.min_trials:
                print ("    Skipping too few trials less than ", self.min_trials)
                continue

            #
            print ("processing; ", fname, " with lockout: ", self.lockout)

            # exclude small # of trial data
            if trial_courses_fixed.shape[0]<=1:
                print ("  Insuffciient trials, exiting...")
                continue

            #
            self.trials = trial_courses_fixed
            self.random = trial_courses_random_fixed
            accuracy, labels, predictions = self.compute_accuracy_svm_KFold()

            #
            np.savez(fname_out,
                    accuracy = accuracy,
                    labels = labels,
                    predictions = predictions)



            #
            #np.save(fname_out,accuracy)

        print ("DONE predicting SVM on animal: ", self.animal_id)
 Predict2 is an updated version which uses sklearn tools for svm instead of
        coding from scratch

        
Predict2 is an updated version which uses sklearn tools for svm instead of
coding from scratch
Predict2 is an updated version which uses sklearn tools for svm instead of coding from scratch
def predict2(self):
        try:
            os.mkdir(os.path.join(self.root_dir, self.animal_id, "SVM_Scores"))
        except:
            pass
        self.get_sessions()
        prefix1 = ''
        if self.lockout:
            prefix1 = '_lockout_'+str(self.lockout_window)+"sec"
        prefix2 = ''
        if self.pca_flag:
            prefix2 = '_pca_'+str(self.pca_var)
        for s in range(len(self.sessions)):
            fname_out = os.path.join(self.root_dir, self.animal_id,'SVM_Scores',
                                 'SVM_Scores_'+
                                 self.sessions[s]+
                                 self.code+
                                 prefix1+
                                 '_trial_ROItimeCourses_'+
                                 str(self.window)+'sec'+
                                 "_Xvalid"+str(self.xvalidation)+
                                 "_Slidewindow"+str(self.sliding_window)+
                                 '.npz'
                                 )
            if os.path.exists(fname_out) and self.overwrite==False:
                print ("   already computed, skipping ...")
                continue
             grab trial and random data
            fname = os.path.join(self.root_dir, self.animal_id,'tif_files',
                                 self.sessions[s],
                                 self.sessions[s]+'_'+
                                 self.code+
                                 prefix1+
                                 '_trial_ROItimeCourses_'+
                                 str(self.window)+'sec'+
                                 prefix2+
                                 '.npy'
                                 )
            try:
                trial_courses_fixed = np.load(fname)
                trial_courses_random_fixed = np.load(fname.replace('trial','random'))
            except:
                print (" ....file not found, skippping ")
                continue
            if trial_courses_fixed.shape[0] < self.min_trials:
                print ("    Skipping too few trials less than ", self.min_trials)
                continue
            print ("processing; ", fname, " with lockout: ", self.lockout)
             exclude small  of trial data
            if trial_courses_fixed.shape[0]<=1:
                print ("  Insuffciient trials, exiting...")
                continue
            self.trials = trial_courses_fixed
            self.random = trial_courses_random_fixed
            accuracy, labels, predictions = self.compute_accuracy_svm_KFold()
            np.savez(fname_out,
                    accuracy = accuracy,
                    labels = labels,
                    predictions = predictions)
            np.save(fname_out,accuracy)
        print ("DONE predicting SVM on animal: ", self.animal_id)
def predict2 ( self ) : try : os . mkdir ( os . path . join ( self . root_dir , self . animal_id , "SVM_Scores" ) ) except : pass self . get_sessions ( ) prefix1 = '' if self . lockout : prefix1 = '_lockout_' + str ( self . lockout_window ) + "sec" prefix2 = '' if self . pca_flag : prefix2 = '_pca_' + str ( self . pca_var ) for s in range ( len ( self . sessions ) ) : fname_out = os . path . join ( self . root_dir , self . animal_id , 'SVM_Scores' , 'SVM_Scores_' + self . sessions [ s ] + self . code + prefix1 + '_trial_ROItimeCourses_' + str ( self . window ) + 'sec' + "_Xvalid" + str ( self . xvalidation ) + "_Slidewindow" + str ( self . sliding_window ) + '.npz' ) if os . path . exists ( fname_out ) and self . overwrite == False : print ( "   already computed, skipping ..." ) continue fname = os . path . join ( self . root_dir , self . animal_id , 'tif_files' , self . sessions [ s ] , self . sessions [ s ] + '_' + self . code + prefix1 + '_trial_ROItimeCourses_' + str ( self . window ) + 'sec' + prefix2 + '.npy' ) try : trial_courses_fixed = np . load ( fname ) trial_courses_random_fixed = np . load ( fname . replace ( 'trial' , 'random' ) ) except : print ( " ....file not found, skippping " ) continue if trial_courses_fixed . shape [ 0 ] < self . min_trials : print ( "    Skipping too few trials less than " , self . min_trials ) continue print ( "processing; " , fname , " with lockout: " , self . lockout ) if trial_courses_fixed . shape [ 0 ] <= 1 : print ( "  Insuffciient trials, exiting..." ) continue self . trials = trial_courses_fixed self . random = trial_courses_random_fixed accuracy , labels , predictions = self . compute_accuracy_svm_KFold ( ) np . savez ( fname_out , accuracy = accuracy , labels = labels , predictions = predictions ) print ( "DONE predicting SVM on animal: " , self . animal_id )
Predict2 is an updated version which uses sklearn tools for svm instead of
coding from scratch
Predict2 is an updated version which uses sklearn tools for svm instead of coding from scratch
''' Predict2 is an updated version which uses sklearn tools for svm instead of
        coding from scratch

        ''' # make SVM_Scores output for animal # find specific session if only 1 chosen # # # # grab trial and random data # # exclude small # of trial data # # # #np.save(fname_out,accuracy)
self