def tag_LFM(self): from tag_LFM import RLTMF tk.messagebox.showinfo('提示', message='已选择算法1进行训练!') self.show_info = tk.Toplevel(self.window_train, bg='pink') self.show_info.geometry('300x250') self.show_info.title('训 练') text = get_text(self.show_info, 100, 10, (200, 200)) text.insert('insert', ' 算法1 训练信息\n') text.update() text.pack() model = RLTMF(2, 2) model.InitList_movielens('jester_ratings.csv') x = [] y = [] for epoch_info in model.fit(): if not isinstance(epoch_info, tuple): text.insert('insert', epoch_info) break x.append(epoch_info[0]) y.append(epoch_info[1]) text.insert('insert', " %3d epoch :MAE is %f\n" % epoch_info) text.update() model.setEvalPara(10) cover = model.Coverage() pre_rec = model.PrecisionRecall() diver = model.Diversity() tk.messagebox.showinfo('模型性能评测', cover+pre_rec+diver) plt.plot(x,y) plt.savefig('train.jpg') self.plot_train()
def coldstart(self): from cold_net import Data_coldStart, cold_model tk.messagebox.showinfo('提示', message='已选择算法3进行训练!') self.show_info = tk.Toplevel(self.window_train, bg='pink') self.show_info.geometry('300x250') self.show_info.title('训 练') text = get_text(self.show_info, 100, 10, (200, 200)) text.insert('insert', ' 算法2 训练信息\n') text.update() text.pack() datapath = r'C:\Users\Darkn\python\recommender\hetrec2011-movielens-2k-v2' dim = 10 data = Data_coldStart() data.get_actor(datapath + r'\movie_actors.dat', weight=20) data.get_country(datapath + r'\movie_countries.dat') data.get_director(datapath + r'\movie_directors.dat') data.get_genres(datapath + r'\movie_genres.dat', weight=30) # data.get_data(DATAPATH + r'\user_ratedmovies.dat') data.read_data() actor_num, country_num, director_num, genre_num = data.size() CM = cold_model(actor_num, country_num, director_num, genre_num, data.train.users, dim) for epoch_info in CM.fit(30, data): text.insert('insert', " %3d epoch :MAE is %f\n" % epoch_info) text.update() self.plot_train()
def push_top_N(self): user = self.entry_user_name.get() top_n = self.recommend_n.get() try: top_n = int(top_n) except BaseException: tk.messagebox.showinfo('错误', message='输入列表长度必须是数字格式!') return if top_n > 100: tk.messagebox.showinfo('错误', message='推荐列表长度设置过大!') return self.model.setEvalPara(int(top_n)) # if not self.flag: # self.text.pack_forget() rec_list = self.model.TopN(user, choice="RATING") if rec_list is None: tk.messagebox.showinfo('错误', message='系统中没有该用户id,请查看【所有用户】!') return push_win = tk.Toplevel(self.mix_recommend, bg='pink') push_win.geometry('200x400') push_win.title('所有用户') text = get_text(push_win, 200, 100, (200, 400)) text.insert('insert', '%s %s %s\n' % ('行号', '物品id', '预测评分')) text.insert( 'insert', '\n'.join([ '%3d %7s %.3f' % (i, item, rating) for i, (item, rating) in enumerate(rec_list) ]))
def prob_FM(self): from prob_lfm import BLFM tk.messagebox.showinfo('提示', message='已选择算法2进行训练!') self.show_info = tk.Toplevel(self.window_train, bg='pink') self.show_info.geometry('300x250') self.show_info.title('训 练') text = get_text(self.show_info, 100, 10, (200, 200)) text.insert('insert', ' 算法2 训练信息\n') text.update() text.pack() model = BLFM('jester_ratings.csv', 25) for epoch_info in model.fit(): text.insert('insert', " %3d epoch :MAE is %f\n" % epoch_info) text.update() self.plot_train()
def show_users(self): self.all_user = tk.Toplevel(self.mix_recommend, bg='pink') self.all_user.geometry('600x600') self.all_user.title('所有用户') self.text = get_text(self.all_user, 200, 100, (200, 200)) self.text.insert('insert', ' 用户列表\n') self.text.update() self.text.pack() num_users = len(self.users) for index in range(0, num_users, 10): self.text.insert( 'insert', ' '.join( ['%6s' % user for user in self.users[index:index + 8]]) + '\n') self.text.update()
def scrap_website(address): """ Scrap text and images from website :param address: website address example: https://www.youtube.com/ :return: true value if done """ web_text = get_text(address) # scrap text web_images_l = get_images_links(address) # scrap images web_images_b = get_images_bytes(web_images_l) # images into bytes row = {} row['Address']=address row['Text']=web_text row['Images']=web_images_b row['Images_links']=web_images_l # add resource to database if data_add_resource(row) is True: #and images in the future return True else: return False
from jam_picamera import JamPiCamera from auth import CON_KEY, CON_SEC, ACC_TOK, ACC_SEC from text import get_text from gpiozero import Button from twython import Twython from time import sleep import logging logger = logging.getLogger('photobooth') logging.basicConfig(level=logging.INFO) logger.info("starting") text = get_text(language='en') camera = JamPiCamera() button = Button(14, hold_time=5) if CON_KEY: twitter = Twython(CON_KEY, CON_SEC, ACC_TOK, ACC_SEC) else: twitter = None camera.resolution = (1024, 768) camera.start_preview() camera.annotate_text_size = 70 def quit(): logger.info("quitting") camera.close()
from jam_picamera import JamPiCamera from text import get_text from gpiozero import Button from time import sleep import logging import subprocess import glob import os logger = logging.getLogger('photobooth') logging.basicConfig(level=logging.INFO) logger.info("starting") text = get_text(language='fr') photo_path = "/home/pi/Pictures" default_photo = os.path.join(os.path.dirname(__file__), "default_photo.jpg") slideshow_delay = 4 slideshow_base = ["fbi", "-a", "--noverbose"] camera = JamPiCamera() button = Button(14, hold_time=5) camera.resolution = (1024, 768) camera.annotate_text_size = 70 #leave the script def quit(): logger.info("quitting") camera.close()
if event.key == pygame.K_d: player.right_moving = False if event.key == pygame.K_a: player.left_moving = False else: if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: start_button.check_input_button(event.pos, click=True) if event.type == pygame.MOUSEBUTTONUP: if event.button == 1 and start_button.check_input_button(event.pos, click=True): start_game = True if start_game is False: # Отрисовка кнопки start_button.draw_button() name_game_text = get_text(path_font, 40, COLOR_NAME_GAME_TEXT, 'GameJam First') surface.blit(name_game_text, (w // 2 - name_game_text.get_width() // 2, name_game_text.get_height())) if start_game: # Отрисовка рекорда score_text = get_text(path_font, 15, COLOR_SCORE, f'score {score}') surface.blit(score_text, (w - score_text.get_width() - 10, score_text.get_height())) scroll[0] += (player_rect.x - scroll[0] - 300) / 10 scroll[1] += (player_rect.y - scroll[1] - 400) / 10 if player_rect.y > h: player.game_over = True player_movement = [0, 0] if player.right_moving: