original_docstring: 
          Prepare the data for train, also train the classifier and make the test data divide by classes.
          :return: The classifier and dict_class_movie_test
          
docstring: Prepare the data for train, also train the classifier and make the test data divide by classes.
docstring_tokens: Prepare the data for train also train the classifier and make the test data divide by classes .
code: def train(self):
          """
          Prepare the data for train, also train the classifier and make the test data divide by classes.
          :return: The classifier and dict_class_movie_test
          """
          path1 = os.path.join(self.args.data_name, f'train/classifier23_{self.args.embedding}_{self.args.norm}.pkl')
          path2 = os.path.join(self.args.data_name, f'train/dict_{self.args.embedding}_{self.args.norm}.pkl')
          if os.path.exists(path1) and os.path.exists(path2):
              with open(path1, 'rb') as handle:
                  classif2 = pickle.load(handle)
              with open(path2, 'rb') as handle:
                  dict_class_movie_test = pickle.load(handle)
          else:
              classes = list(self.dict_true_edges.keys())
              for i, k in enumerate(sorted(self.dict_true_edges, key=lambda k: len(self.dict_true_edges[k]), reverse=True)):
                  classes[i] = k
              dict_class_movie_test = {}
              X_train_all, Y_train_all = np.array([]), np.array([])
              seen_classes = classes[:int(0.8 * len(classes))]
              unseen_classes = classes[int(0.8 * len(classes)):]
              for j in range(len(self.args.ratio)):
                  for c in seen_classes:
                      dict_movie_edge = {}
                      X_true, X_false, Y_true_edge, Y_false_edge = \
                          self.calculate_classifier_value(self.dict_true_edges[c], self.dict_false_edges[c])
                      X_train, Y_train, true_edges_test = self.split_data(X_true, X_false, Y_true_edge, Y_false_edge, self.args.ratio[j])
                      for edge in true_edges_test:
                          if edge[0][0] == 't':
                              movie = edge[0]
                          else:
                              movie = edge[1]
                          dict_movie_edge[movie] = edge
                      dict_class_movie_test[c] = dict_movie_edge.copy()
                      if len(X_train_all) > 0:
                          X_train_all = np.concatenate((X_train_all, X_train), axis=0)
                          Y_train_all = np.concatenate((Y_train_all, Y_train), axis=0)
                      else:
                          X_train_all = X_train
                          Y_train_all = Y_train
                  for c in unseen_classes:
                      dict_movie_edge = {}
                      X_true, X_false, Y_true_edge, Y_false_edge = \
                          self.calculate_classifier_value(self.dict_true_edges[c], self.dict_false_edges[c])
                      _, _, true_edges_test = self.split_data(X_true, X_false, Y_true_edge, Y_false_edge, ratio=0)
                      for edge in true_edges_test:
                          if edge[0][0] == 't':
                              movie = edge[0]
                          else:
                              movie = edge[1]
                          dict_movie_edge[movie] = edge
                      dict_class_movie_test[c] = dict_movie_edge.copy()
                  shuff = np.c_[X_train_all.reshape(len(X_train_all), -1), Y_train_all.reshape(len(Y_train_all), -1)]
                  np.random.shuffle(shuff)
                  X_train_all = shuff.T[0].reshape(-1, 1)
                  Y_train_all = np.array([shuff.T[1].reshape(-1, 1), shuff.T[2].reshape(-1, 1)]).T.reshape(-1, 2).astype(
                      int)
                  classif2 = self.train_edge_classification(np.array(X_train_all), np.array(Y_train_all))
                  with open(path1, 'wb') as fid:
                      pickle.dump(classif2, fid)
                  with open(path2, 'wb') as fid:
                      pickle.dump(dict_class_movie_test, fid)
          return classif2, dict_class_movie_test
code_tokens: def train ( self ) : path1 = os . path . join ( self . args . data_name , f'train/classifier23_{self.args.embedding}_{self.args.norm}.pkl' ) path2 = os . path . join ( self . args . data_name , f'train/dict_{self.args.embedding}_{self.args.norm}.pkl' ) if os . path . exists ( path1 ) and os . path . exists ( path2 ) : with open ( path1 , 'rb' ) as handle : classif2 = pickle . load ( handle ) with open ( path2 , 'rb' ) as handle : dict_class_movie_test = pickle . load ( handle ) else : classes = list ( self . dict_true_edges . keys ( ) ) for i , k in enumerate ( sorted ( self . dict_true_edges , key = lambda k : len ( self . dict_true_edges [ k ] ) , reverse = True ) ) : classes [ i ] = k dict_class_movie_test = { } X_train_all , Y_train_all = np . array ( [ ] ) , np . array ( [ ] ) seen_classes = classes [ : int ( 0.8 * len ( classes ) ) ] unseen_classes = classes [ int ( 0.8 * len ( classes ) ) : ] for j in range ( len ( self . args . ratio ) ) : for c in seen_classes : dict_movie_edge = { } X_true , X_false , Y_true_edge , Y_false_edge = self . calculate_classifier_value ( self . dict_true_edges [ c ] , self . dict_false_edges [ c ] ) X_train , Y_train , true_edges_test = self . split_data ( X_true , X_false , Y_true_edge , Y_false_edge , self . args . ratio [ j ] ) for edge in true_edges_test : if edge [ 0 ] [ 0 ] == 't' : movie = edge [ 0 ] else : movie = edge [ 1 ] dict_movie_edge [ movie ] = edge dict_class_movie_test [ c ] = dict_movie_edge . copy ( ) if len ( X_train_all ) > 0 : X_train_all = np . concatenate ( ( X_train_all , X_train ) , axis = 0 ) Y_train_all = np . concatenate ( ( Y_train_all , Y_train ) , axis = 0 ) else : X_train_all = X_train Y_train_all = Y_train for c in unseen_classes : dict_movie_edge = { } X_true , X_false , Y_true_edge , Y_false_edge = self . calculate_classifier_value ( self . dict_true_edges [ c ] , self . dict_false_edges [ c ] ) _ , _ , true_edges_test = self . split_data ( X_true , X_false , Y_true_edge , Y_false_edge , ratio = 0 ) for edge in true_edges_test : if edge [ 0 ] [ 0 ] == 't' : movie = edge [ 0 ] else : movie = edge [ 1 ] dict_movie_edge [ movie ] = edge dict_class_movie_test [ c ] = dict_movie_edge . copy ( ) shuff = np . c_ [ X_train_all . reshape ( len ( X_train_all ) , - 1 ) , Y_train_all . reshape ( len ( Y_train_all ) , - 1 ) ] np . random . shuffle ( shuff ) X_train_all = shuff . T [ 0 ] . reshape ( - 1 , 1 ) Y_train_all = np . array ( [ shuff . T [ 1 ] . reshape ( - 1 , 1 ) , shuff . T [ 2 ] . reshape ( - 1 , 1 ) ] ) . T . reshape ( - 1 , 2 ) . astype ( int ) classif2 = self . train_edge_classification ( np . array ( X_train_all ) , np . array ( Y_train_all ) ) with open ( path1 , 'wb' ) as fid : pickle . dump ( classif2 , fid ) with open ( path2 , 'wb' ) as fid : pickle . dump ( dict_class_movie_test , fid ) return classif2 , dict_class_movie_test
short_docstring: Prepare the data for train, also train the classifier and make the test data divide by classes.
short_docstring_tokens: Prepare the data for train also train the classifier and make the test data divide by classes .
comment: """
          Prepare the data for train, also train the classifier and make the test data divide by classes.
          :return: The classifier and dict_class_movie_test
          """