recommendation/model_reco.py
def load_corpus(self, corpus_path=os.path.join(ROOT_DIR, 'corpus/iot-tweets-vector-v31.tsv'),
					like_rt_graph=os.path.join(ROOT_DIR, 'corpus/like_rt_graph.adj')):
		"""
		Load the corpus and the Favorite/RT adjancy matrix
		:param corpus_path: absolute path
		:param like_rt_graph: absolute path
		:return: pd.DataFrame object
		"""

		original_corpus = Parser.parsing_base_corpus_pandas(corpus_path, categorize=True)

		self.num_users = len(original_corpus.User_Name.unique())
		self.num_tweets = len(original_corpus.TweetID.unique())

		corpus = original_corpus[['User_ID_u', 'TweetID_u']]

		like_rt_file = open(like_rt_graph, 'r')
		for line in like_rt_file:
			parts = line[:-1].split(' ')
			user_name = parts[0]
			user_id = original_corpus[original_corpus.User_Name == user_name].User_ID_u.iloc[0]
			tweets = parts[1:]  # like or RT tweets

			for tweet in tweets:
				if len(original_corpus[original_corpus.TweetID == int(tweet)]) > 0:
					tweet_id = original_corpus[original_corpus.TweetID == int(tweet)].TweetID_u.iloc[0]

					corpus = corpus.append({'User_ID_u': user_id, 'TweetID_u': tweet_id}, ignore_index=True)

		like_rt_file.close()

		corpus['Rating'] = 1

		for index, line in corpus.iterrows():
			u = line.User_ID_u

			# negative instances
			for t in range(self.num_negatives):
				j = np.random.randint(self.num_tweets)
				while (u, j) in corpus[['User_ID_u', 'TweetID_u']]:
					j = np.random.randint(self.num_tweets)

				corpus = corpus.append({'User_ID_u': u, 'TweetID_u': j, 'Rating': 0}, ignore_index=True)

		self.train_corpus, self.test_corpus = train_test_split(corpus, test_size=0.2)
		return self.train_corpus, self.test_corpus

		Load the corpus and the Favorite/RT adjancy matrix
		:param corpus_path: absolute path
		:param like_rt_graph: absolute path
		:return: pd.DataFrame object
		
Load the corpus and the Favorite/RT adjancy matrix
Load the corpus and the Favorite / RT adjancy matrix
def load_corpus(self, corpus_path=os.path.join(ROOT_DIR, 'corpus/iot-tweets-vector-v31.tsv'),
					like_rt_graph=os.path.join(ROOT_DIR, 'corpus/like_rt_graph.adj')):
		original_corpus = Parser.parsing_base_corpus_pandas(corpus_path, categorize=True)
		self.num_users = len(original_corpus.User_Name.unique())
		self.num_tweets = len(original_corpus.TweetID.unique())
		corpus = original_corpus[['User_ID_u', 'TweetID_u']]
		like_rt_file = open(like_rt_graph, 'r')
		for line in like_rt_file:
			parts = line[:-1].split(' ')
			user_name = parts[0]
			user_id = original_corpus[original_corpus.User_Name == user_name].User_ID_u.iloc[0]
			tweets = parts[1:]  
			for tweet in tweets:
				if len(original_corpus[original_corpus.TweetID == int(tweet)]) > 0:
					tweet_id = original_corpus[original_corpus.TweetID == int(tweet)].TweetID_u.iloc[0]
					corpus = corpus.append({'User_ID_u': user_id, 'TweetID_u': tweet_id}, ignore_index=True)
		like_rt_file.close()
		corpus['Rating'] = 1
		for index, line in corpus.iterrows():
			u = line.User_ID_u
			for t in range(self.num_negatives):
				j = np.random.randint(self.num_tweets)
				while (u, j) in corpus[['User_ID_u', 'TweetID_u']]:
					j = np.random.randint(self.num_tweets)
				corpus = corpus.append({'User_ID_u': u, 'TweetID_u': j, 'Rating': 0}, ignore_index=True)
		self.train_corpus, self.test_corpus = train_test_split(corpus, test_size=0.2)
		return self.train_corpus, self.test_corpus
def load_corpus ( self , corpus_path = os . path . join ( ROOT_DIR , 'corpus/iot-tweets-vector-v31.tsv' ) , like_rt_graph = os . path . join ( ROOT_DIR , 'corpus/like_rt_graph.adj' ) ) : original_corpus = Parser . parsing_base_corpus_pandas ( corpus_path , categorize = True ) self . num_users = len ( original_corpus . User_Name . unique ( ) ) self . num_tweets = len ( original_corpus . TweetID . unique ( ) ) corpus = original_corpus [ [ 'User_ID_u' , 'TweetID_u' ] ] like_rt_file = open ( like_rt_graph , 'r' ) for line in like_rt_file : parts = line [ : - 1 ] . split ( ' ' ) user_name = parts [ 0 ] user_id = original_corpus [ original_corpus . User_Name == user_name ] . User_ID_u . iloc [ 0 ] tweets = parts [ 1 : ] for tweet in tweets : if len ( original_corpus [ original_corpus . TweetID == int ( tweet ) ] ) > 0 : tweet_id = original_corpus [ original_corpus . TweetID == int ( tweet ) ] . TweetID_u . iloc [ 0 ] corpus = corpus . append ( { 'User_ID_u' : user_id , 'TweetID_u' : tweet_id } , ignore_index = True ) like_rt_file . close ( ) corpus [ 'Rating' ] = 1 for index , line in corpus . iterrows ( ) : u = line . User_ID_u for t in range ( self . num_negatives ) : j = np . random . randint ( self . num_tweets ) while ( u , j ) in corpus [ [ 'User_ID_u' , 'TweetID_u' ] ] : j = np . random . randint ( self . num_tweets ) corpus = corpus . append ( { 'User_ID_u' : u , 'TweetID_u' : j , 'Rating' : 0 } , ignore_index = True ) self . train_corpus , self . test_corpus = train_test_split ( corpus , test_size = 0.2 ) return self . train_corpus , self . test_corpus
Load the corpus and the Favorite/RT adjancy matrix
Load the corpus and the Favorite / RT adjancy matrix
"""
		Load the corpus and the Favorite/RT adjancy matrix
		:param corpus_path: absolute path
		:param like_rt_graph: absolute path
		:return: pd.DataFrame object
		""" # like or RT tweets # negative instances
None
self
corpus_path
None
like_rt_graph
None