def slicingUIM(U, I): #Storing UIM values for indices in I and U for respective axes M = UIM.iloc[I, U] #Square and sum across users M2 = (M * M).sum(0) #Sort M and return the top n indices return pd.argsort(M2)[:top_n]
def wildcard(uid): mainList = pd.argsort(finalscore(uid))[:9].tolist() dropList = [] dropList = dropList.append(mainList).append(genI(uid)) wildIIDList = pd.DataFrame(np.arange(5000)).drop(dropList) upList = wildIIDList.apply(lambda i: len(genI(i)) + 1) hm = scipy.stats.hmean(upList) length = wildIIDList.size() k = hm / length pList = wildIIDList.apply(lambda i: k / (len(genI(i)) + 1)) wildIID = np.random.choice(wildIIDList, 1, True, pList)[0] return random.shuffle(mainList.append(wildIID))
def icfscore(uid, iid): I = initI_noIID(uid) U = genU(iid) #Storing top user indices U1 = pd.argsort(UUM[uid, U])[:top_n].tolist() return slicingUIM(U1, I)
def cbscore(uid, iid): I = initI_noIID(uid) #Storing the IIM values of this iid column restricted to indices in I M = IIM.iloc[I, iid] #Sort M and return the top n indices return pd.argsort(M)[:top_n]