Added pruning of connections from recommenders (above maximum threshold)
and tweaked some params
This commit is contained in:
parent
a5352dd794
commit
ad38e3e2a2
36
main.py
36
main.py
@ -170,6 +170,31 @@ def pruneTags(G, minCons=2):
|
||||
if foundCon > minCons:
|
||||
G.remove_node(n)
|
||||
|
||||
def pruneRecommenderCons(G, maxCons=5):
|
||||
for n in list(G.nodes):
|
||||
node = G.nodes[n]
|
||||
if node['t'] == 'recommender':
|
||||
if len(G.adj[n]) > maxCons:
|
||||
bestlist = []
|
||||
for m in list(G.adj[n]):
|
||||
book = G.nodes[m]
|
||||
if book['t'] == 'book':
|
||||
if 'score' in book and book['score'] != None:
|
||||
bestlist.append(book)
|
||||
bestlist.sort(key=lambda node: node['score'], reverse=True)
|
||||
bestlist = bestlist[:maxCons]
|
||||
|
||||
for m in list(G.adj[n]):
|
||||
book = G.nodes[m]
|
||||
if book['t'] == 'book' and book not in bestlist or 'score' in book and book['score'] == None:
|
||||
if not 'rating' in book or book['rating'] == None:
|
||||
foundCon = 0
|
||||
for con in G.adj[m]:
|
||||
if G.nodes[con]['t'] not in ['topList']:
|
||||
foundCon += 1
|
||||
if foundCon < 2:
|
||||
G.remove_node(m)
|
||||
|
||||
|
||||
def removeHighSpanTags(G, maxCons=5):
|
||||
for n in list(G.nodes):
|
||||
@ -202,7 +227,7 @@ def removeRestOfSeries(G):
|
||||
G.remove_node(adj)
|
||||
|
||||
|
||||
def scoreOpinions(G, globMu, globStd, errorFac=1.2):
|
||||
def scoreOpinions(G, globMu, globStd, errorFac=0.7):
|
||||
for n in list(G.nodes):
|
||||
node = G.nodes[n]
|
||||
feedbacks = []
|
||||
@ -217,14 +242,14 @@ def scoreOpinions(G, globMu, globStd, errorFac=1.2):
|
||||
node['se'] = globStd / math.sqrt(len(feedbacks))
|
||||
ratio = len(feedbacks) / len(adjacens)
|
||||
node['score'] = node['mean'] - errorFac * \
|
||||
node['se']*(9/10 + (1-ratio)/10) + 0.001 * \
|
||||
node['se']*(6/7 + (1-ratio)/7) + 0.001 * \
|
||||
(node['t'] == 'recommender')
|
||||
node['feedbacks'] = feedbacks
|
||||
else:
|
||||
node['score'] = None
|
||||
|
||||
|
||||
def scoreUnread(G, globMu, globStd, errorFac=1):
|
||||
def scoreUnread(G, globMu, globStd, errorFac=0.6):
|
||||
for n in list(G.nodes):
|
||||
feedbacks = []
|
||||
deepFeedbacks = []
|
||||
@ -440,6 +465,7 @@ def recommendNBooks(n):
|
||||
pruneTags(G, 4)
|
||||
removeBad(G, mu, groups=['book'])
|
||||
pruneTags(G, 3)
|
||||
pruneRecommenderCons(G, 5)
|
||||
removeTopLists(G)
|
||||
removeDangling(G, alsoBooks=True)
|
||||
removeKeepBest(G, n, maxDistForRead=0.75)
|
||||
@ -451,7 +477,7 @@ def recommendNBooks(n):
|
||||
addScoreToLabels(G)
|
||||
|
||||
printBestList(G, num=n)
|
||||
genAndShowHTML(G)
|
||||
genAndShowHTML(G, True)
|
||||
|
||||
|
||||
def fullGraph():
|
||||
@ -495,4 +521,4 @@ def readBooksAnalysis():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
recommendNBooks(30)
|
||||
recommendNBooks(35)
|
||||
|
Loading…
Reference in New Issue
Block a user