예제 #1
0
class Data(object):
    """
    Keeps the data setup that it will pass to the gui and the gui will then update and interact with it
    """
    
    def __init__(self):
        """
        Sets up the data 
        """
        self._y=[]
        self._dic_of_names={}
        self._names_int={}
        self._names_count=0
        self._X=[]
        self._clf=Clf().clf
        
    def get_names(self):
        """
        Returns a list of all the current labeled names besides the Unknown value.
        """
        lst = self._names_int.keys()
        if 'Unknown' in lst:
            lst.remove('Unknown')
        if len(lst)>2:
            lst=sorted(lst)
        return lst
    
    def add_data(self,X,y,path):
        """
        If the model is fit then it will return the best predicted guess
        """
        ##add tags on the file
        add_attr_to_file(y,path)
        
        ##keeps the currect name_dict 
        if y not in self._names_int:
            self._dic_of_names[self._names_count]=y
            self._names_int[y]=self._names_count
            self._names_count +=1
        self._y.append(self._names_int[y])
        self._X.append(X)
        
        ##The n of the pca and lda n will adjust based off of size of training data
        ##It will train after size of 15 and retain after every 5 new inputs 
        if len(self._y)%5==0 and self._names_count>1 and len(self._y)>15:
            self._clf=Clf(
                pca_n=100,
                lda_n=len(set(self._y))
            ).clf.fit(self._X,self._y)
    
    def get_best_guess(self,X):
        """
        If the model is fit then it will return the best predicted guess
        """
        try:
            return self._dic_of_names[self._clf.predict(X)[0]]
        except NotFittedError:
            pass
        return None
예제 #2
0
 def __init__(self):
     """
     Sets up the data 
     """
     self._y=[]
     self._dic_of_names={}
     self._names_int={}
     self._names_count=0
     self._X=[]
     self._clf=Clf().clf
예제 #3
0
 def add_data(self,X,y,path):
     """
     If the model is fit then it will return the best predicted guess
     """
     ##add tags on the file
     add_attr_to_file(y,path)
     
     ##keeps the currect name_dict 
     if y not in self._names_int:
         self._dic_of_names[self._names_count]=y
         self._names_int[y]=self._names_count
         self._names_count +=1
     self._y.append(self._names_int[y])
     self._X.append(X)
     
     ##The n of the pca and lda n will adjust based off of size of training data
     ##It will train after size of 15 and retain after every 5 new inputs 
     if len(self._y)%5==0 and self._names_count>1 and len(self._y)>15:
         self._clf=Clf(
             pca_n=100,
             lda_n=len(set(self._y))
         ).clf.fit(self._X,self._y)