def e_scenr(peer, name, ayd):
    if type(peer) != type("str"):
       peer = str(peer)
    d = getdata(peer) #Получаем данные

    d[name] = ayd #Далее ничего не назначаем, тк мы передаем ссылку на объект
    write("custom/preset_%s.pref"%(peer), json.dumps(d))
Beispiel #2
0
def fun1():
    data = pd.read_csv('./data/train.csv')
    data = data[['user_id','brand_id','type','month','day']]
    data = np.array(data)
    user_id = func.read('user_id')
    user_time_item = func.build_user_time_item(data,user_id)
    func.write(user_time_item,'user_time_item')
Beispiel #3
0
def cross_valation(K,train_u_i_t,test_u_i,item_time,item_factor):
    day_count = 91
    #获取训练集的推荐列表
    M=3.5
    rec_user_item = usermodel.build_user_model(train_u_i_t,item_factor,day_count)
    
    #在这里进行一次测试,对用户的推荐列表,只推荐值大于某一限定的物品
    rec_user_item,former_rec = func.set_min_M(rec_user_item,M)
    #需要对推荐列表进行处理,对每个用户设定推荐的物品的个数,K为设定的物品的个数
    rec_user_item = func.set_rec_item_num(rec_user_item,K)
    #接下来想做的处理是,对冷启动用户,给其添加浏览过的热门商品(效果不好)
    #rec_user_item = func.cal_cold_start(rec_user_item,former_rec,item_time)
    #查看分布
    func.check_distribuction(rec_user_item)
    #计算准确率,召回率,F值等参数
    hit_user_item = func.cal_hit_user_item(rec_user_item,test_u_i) 
    precision,recall,F,hitbrand,pbrand,bbrand = func.cal_result(rec_user_item,test_u_i,hit_user_item)
    
    func.write(rec_user_item,'train_rec_user_item')
    func.write(hit_user_item,'hit_user_item')
    
    print '限定对每个用户推荐的物品数为:',K
    print 'hitbrand',hitbrand,'pbrand',pbrand,'precision',precision
    print 'hitbrand',hitbrand,'bbrand',bbrand,'recall',recall
    print 'F',F
Beispiel #4
0
def getdata(peer):
    f = read("userdata/user_%s.pref" % (peer))
    if not f:
        d = _basic
        write("userdata/user_%s.pref" % (peer), json.dumps(d))
    else:
        d = json.loads(f)
    return d
def getdata(peer):
    d = {}
    f = read("custom/preset_%s.pref"%(peer))
    if not f:
        d = _basic
        write("custom/preset_%s.pref"%(peer), json.dumps(d))
    else:
        d = json.loads(f)
    return d
def _scenr(peer, name):
    if type(peer) != type("str"):
       peer = str(peer)
    d = getdata(peer) #Получаем данные

    if not name in d: #Если данные еще не получены
        d[name] = _basic[name]
        write("custom/preset_%s.pref"%(peer), json.dumps(d))
        return d[name]
    else: 
        return d[name]
Beispiel #7
0
def func2():
    data = pd.read_csv('./data/train.csv')
    data = data[['user_id','brand_id','type','month','day']]
    data = np.array(data)
    user_id = func.read('user_id')
    item_id = func.read('item_id')

    user_item_time = func.build_user_item_time(data,user_id)
    item_time = itemmodel.build_item_time(data,item_id)
    item_factor = itemmodel.cal_item_time_factor(item_time)
    func.write(user_item_time,'user_item_time')
    func.write(item_time,'item_time')
    return (user_item_time,item_time,item_factor)
Beispiel #8
0
def func4():
    user_item_time,item_time,item_factor = func2()
    K = 20
    M=4
    day_count = 123
    
    rec_user_item = usermodel.build_user_model(user_item_time,item_factor,day_count)
    rec_user_item,former_rec = func.set_min_M(rec_user_item,M)
    rec_user_item = func.set_rec_item_num(rec_user_item,K)
    #查看为用户推荐物品的个数分布,对有那些推荐物品个数小于等于3的用户给其推荐热门商品
    #查看分布
    func.check_distribuction(rec_user_item)
    #rec_user_item=func.distribution(rec_user_item)
    func.write(rec_user_item,'rec_user_item')
    
    func.getresult(rec_user_item)
Beispiel #9
0
	def render(self, surface, time, objects, ox=0, oy=0):

		if not self.pickedUp:
			surface.blit(self.texture, (GRIDX+GRATIO*self.x+ox-self.tWidth//4,GRIDY+GRATIO*self.y+oy-self.tHeight//4))
			if self.price != 0:
				surface.blit(func.write(str(self.price), self.digits, dark=0), (GRIDX+GRATIO*self.x+ox-5,GRIDY+GRATIO*self.y+oy+35))
		return not self.pickedUp
Beispiel #10
0
def index():
    ""
    ''' We store guest messages in a json file.
    First we open it to load the data.
    Then we pass the data to the read() function to transform it into the (<name>, <date>, <message>) format.
    The transformed data will become a list containing the rows with the format above.
    Finally we can pass the list to render_template() to display the messages when we visit index.html.
    '''
    with open('data.json', 'r') as file:
        data = json.load(file)
        rows = read(data)
        num_messages_to_show = checkLen(rows) # We also want to check how many messages are in the data

    # Here we instantiate a form object
    form = InputForm()

    ''' If the user enters valid inputs and presses Post, the code block below will run.
    We retrieve the user's name and message and store them in name and message.
    Then we update the rows list to add the received message and return it.
    Finally we can update the data json file using json.dump().    
    '''
    if form.validate_on_submit():
        name = form.name.data
        message = form.message.data

        data = write(rows, name, message)
        with open('data.json', 'w') as file:
            json.dump(data, file)

        return redirect(url_for('index')) # We also want to refresh the index page to show the change

    # In the render_template, you can pass the variables to be used in the html file. This is to connect the back-end to the front-end
    return render_template('index.html', rows=rows, num_messages_to_show=num_messages_to_show, form=form)
Beispiel #11
0
	def render(self, surface, time, objects, ox=0, oy=0):
		# Render the heart on the ground
		if not self.pickedUp:
			# draw.rect(surface, (255,0,0), self.bounds)
			surface.blit(self.texture, (GRIDX+GRATIO*self.x-self.width//4+ox,GRIDY+GRATIO*self.y-self.height//4+oy))
			if self.price != 0:
				surface.blit(func.write(str(self.price), self.digits, dark=0), (GRIDX+GRATIO*self.x+ox-5,GRIDY+GRATIO*self.y+oy+35))
		return not self.pickedUp
Beispiel #12
0
 def render(self, surface, time, objects, ox=0, oy=0):
     # Render the heart on the ground
     if not self.pickedUp:
         # draw.rect(surface, (255,0,0), self.bounds)
         surface.blit(self.texture,
                      (GRIDX + GRATIO * self.x - self.width // 4 + ox,
                       GRIDY + GRATIO * self.y - self.height // 4 + oy))
         if self.price != 0:
             surface.blit(func.write(str(self.price), self.digits, dark=0),
                          (GRIDX + GRATIO * self.x + ox - 5,
                           GRIDY + GRATIO * self.y + oy + 35))
     return not self.pickedUp
Beispiel #13
0
def func3():
    train,test = func.divide_data()
    user_id =  func.read('user_id')
    item_id = func.read('item_id')
    train_u_i_t = func.build_user_item_time(train,user_id)
    #建立测试集的用户-物品词典,这里不需要时间序列
    test_u_i  = func.build_user_item(test,user_id)
    #建立训练集的物品-时间词典
    train_item_time = itemmodel.build_item_time(train,item_id)
    #建立物品的时间衰减因子
    item_factor = itemmodel.cal_item_time_factor(train_item_time)

    func.write(train_u_i_t,'train_user_item_time')
    func.write(test_u_i,'test_user_item')
    func.write(train_item_time,'train_item_time')
    return (train_u_i_t,test_u_i,train_item_time,item_factor)
Beispiel #14
0
def upd(ad, d):
    if type(ad) != type("str"):
        ad = str(ad)
    write("userdata/user_%s.pref" % (ad), json.dumps(d))