示例#1
0
文件: display.py 项目: zzh6333/RecQ
 def __init__(self, conf):
     self.conf = conf
     if not conf.contains('ratings') and not conf.contains('social'):
         print 'The config file is not in the correct format!'
         exit(-1)
     if conf.contains('ratings'):
         ratingData = FileIO.loadDataSet(conf, conf['ratings'])
         self.dao = RatingDAO(conf, ratingData)
     if conf.contains('social'):
         relationData = FileIO.loadRelationship(conf, conf['social'])
         self.sao = SocialDAO(conf, relationData)
示例#2
0
    def __init__(self,conf,trainingSet=None,testSet=None,relation=list(),fold='[1]'):
        super(SocialRecommender, self).__init__(conf,trainingSet,testSet,fold)
        self.social = SocialDAO(self.config,relation) #social relations access control

        # data clean
        cleanList = []
        cleanPair = []
        for user in self.social.followees:
            if not self.data.user.has_key(user):
                cleanList.append(user)
            for u2 in self.social.followees[user]:
                if not self.data.user.has_key(u2):
                    cleanPair.append((user, u2))
        for u in cleanList:
            del self.social.followees[u]

        for pair in cleanPair:
            if self.social.followees.has_key(pair[0]):
                del self.social.followees[pair[0]][pair[1]]

        cleanList = []
        cleanPair = []
        for user in self.social.followers:
            if not self.data.user.has_key(user):
                cleanList.append(user)
            for u2 in self.social.followers[user]:
                if not self.data.user.has_key(u2):
                    cleanPair.append((user, u2))
        for u in cleanList:
            del self.social.followers[u]

        for pair in cleanPair:
            if self.social.followers.has_key(pair[0]):
                del self.social.followers[pair[0]][pair[1]]
示例#3
0
 def __init__(self,
              conf,
              trainingSet=None,
              testSet=None,
              relation=list(),
              fold='[1]'):
     super(SocialRecommender, self).__init__(conf, trainingSet, testSet,
                                             fold)
     self.sao = SocialDAO(self.config,
                          relation)  #social relations access control
示例#4
0
    def __init__(self, conf, trainingSet, testSet, relation, fold='[1]'):
        super(SocialRecommender, self).__init__(conf, trainingSet, testSet,
                                                fold)
        self.social = SocialDAO(self.config,
                                relation)  #social relations access control

        # data clean
        cleanList = []
        cleanPair = []
        for user in self.social.followees:
            if user not in self.data.user:
                cleanList.append(user)
            for u2 in self.social.followees[user]:
                if u2 not in self.data.user:
                    cleanPair.append((user, u2))
        for u in cleanList:
            del self.social.followees[u]

        for pair in cleanPair:
            if pair[0] in self.social.followees:
                del self.social.followees[pair[0]][pair[1]]

        cleanList = []
        cleanPair = []
        for user in self.social.followers:
            if user not in self.data.user:
                cleanList.append(user)
            for u2 in self.social.followers[user]:
                if u2 not in self.data.user:
                    cleanPair.append((user, u2))
        for u in cleanList:
            del self.social.followers[u]

        for pair in cleanPair:
            if pair[0] in self.social.followers:
                del self.social.followers[pair[0]][pair[1]]

        idx = []
        for n, pair in enumerate(self.social.relation):
            if pair[0] not in self.data.user or pair[1] not in self.data.user:
                idx.append(n)

        for item in reversed(idx):
            del self.social.relation[item]
示例#5
0
文件: display.py 项目: zzh6333/RecQ
class Display(object):
    def __init__(self, conf):
        self.conf = conf
        if not conf.contains('ratings') and not conf.contains('social'):
            print 'The config file is not in the correct format!'
            exit(-1)
        if conf.contains('ratings'):
            ratingData = FileIO.loadDataSet(conf, conf['ratings'])
            self.dao = RatingDAO(conf, ratingData)
        if conf.contains('social'):
            relationData = FileIO.loadRelationship(conf, conf['social'])
            self.sao = SocialDAO(conf, relationData)

    def draw(self):
        print 'draw chart...'
        #rating
        if self.conf.contains('ratings'):
            y = [triple[2] for triple in self.dao.trainingData]
            x = self.dao.rScale
            if len(x) < 20:
                Chart.hist(x, y, len(self.dao.rScale), '#058edc',
                           'Rating Histogram', 'Rating Scale', 'Count',
                           '../visual/visualization/images/rh')
            y = [len(self.dao.userRated(u)[0]) for u in self.dao.user]
            Chart.distribution(y, 'Rating Count Distribution', '',
                               'Rated items count per user',
                               '../visual/visualization/images/rcu')
            y = [len(self.dao.itemRated(i)[0]) for i in self.dao.item]
            Chart.distribution(y, 'Rating Count Distribution', '',
                               'user Rated count per item',
                               '../visual/visualization/images/rci')

        #social
        if self.conf.contains('social'):
            x = [len(self.sao.getFollowers(u)) for u in self.sao.user]
            y = [len(self.sao.getFollowees(u)) for u in self.sao.user]
            Chart.scatter(x, y, 'red', 'Follower&Followee', 'Follower count',
                          'Followee count',
                          '../visual/visualization/images/ff')
            y = [len(self.sao.getFollowers(u)) for u in self.sao.user]
            Chart.distribution(y, 'Followers Distribution', '',
                               'Followers count per user',
                               '../visual/visualization/images/fd1')
            y = [len(self.sao.getFollowees(u)) for u in self.sao.user]
            Chart.distribution(y, 'Followees Distribution', '',
                               'Followees count per user',
                               '../visual/visualization/images/fd2')

    def render(self):
        self.draw()
        html ="<html><head><title>Data Analysis</title>\n" \
              "<link rel='stylesheet' type='text/css' href='reportStyle.css'/></head>\n" \
              "<body><div class='reportTitle'><div class='in'>Data Analysis</div></div>\n" \
              "<div class='main'><div class='area1'>\n" \
              "<div class='title'><h3>Data Files</h3></div><div class='text'>"
        if self.conf.contains('ratings'):
            html += "<b>Rating Data</b>: {rating}".format(
                rating=abspath(self.conf['ratings']))
        if self.conf.contains('social'):
            html += "<br><b>Social Data</b>: {social}".format(
                social=abspath(self.conf['social']))
        html+="</div></div><div style='padding-top:20px'><center>" \
              "<img src='images/header2.png'/></center></div>\n"
        if self.conf.contains('ratings'):
            html += "<div class='area1'><div class='title'><h3>Rating Data</h3></div>\n"
            html += "<div class='text'><b>Rating Scale</b>: {scale}</br>".format(
                scale=' '.join([str(item) for item in self.dao.rScale]))
            html += "<b>User Count</b>: {user}<br><b>Item Count</b>: {item}<br><b>Record Count</b>: {record}<br><b>Global Mean</b>: {mean}</div>\n"\
                .format(user = str(len(self.dao.user)),item=str(len(self.dao.item)),record = str(len(self.dao.trainingData)),
                        mean = str(round(denormalize(self.dao.globalMean,self.dao.rScale[-1],self.dao.rScale[0]),3)))
            html += "<center><div class='img'><img src='images/rh.png' width='640px' height='480px'/></div></center>\n"
            html += "<center><div class='img'><img src='images/rcu.png' width='640px' height='480px'/></div></center>\n"
            html += "<center><div class='img'><img src='images/rci.png' width='640px' height='480px'/></div></center>\n"
            html += "</div><div style='padding-top:20px'><center>" \
              "<img src='images/header2.png'/></center></div>\n"
        if self.conf.contains('social'):
            html += "<div class='area1'><div class='title'><h3>Social Data</h3></div>\n"
            html += "<div class='text'><b>User Count</b>: {user}<br><b>Relation Count</b>: {relation}<br></div>\n" \
                .format(user=str(len(self.sao.user)), relation=str(len(self.sao.relation)))
            html += "<center><div class='img'><img src='images/ff.png' width='640px' height='480px'/></div></center>\n"
            html += "<center><div class='img'><img src='images/fd1.png' width='640px' height='480px'/></div></center>\n"
            html += "<center><div class='img'><img src='images/fd2.png' width='640px' height='480px'/></div></center>\n"
            html += "</div><div style='padding-top:20px'><center>" \
                    "<img src='images/header2.png'/></center></div>\n"

        html += "</div></body></html>"
        FileIO.writeFile('../visual/visualization/', 'analysis.html', html)
        print 'The report has been output to', abspath(
            '../visual/visualization/analysis.html')
        webbrowser.open(abspath('../visual/visualization/analysis.html'),
                        new=0,
                        autoraise=True)
示例#6
0
 def __init__(self, conf):
     super(SocialRecommender, self).__init__(conf)
     self.sao = SocialDAO(self.config)  #social relations access control
示例#7
0
    def __init__(self,
                 conf,
                 trainingSet,
                 testSet,
                 relation,
                 inform1,
                 inform2,
                 fold='[1]'):
        super(MetaRecommender, self).__init__(conf, trainingSet, testSet, fold)
        self.social = SocialDAO(self.config,
                                relation)  #social relations access control
        self.meta = MetaDAO(self.config, inform1, inform2)

        # data clean
        cleanList = []
        cleanPair = []
        for user in self.social.followees:
            if not self.data.user.has_key(user):
                cleanList.append(user)
            for u2 in self.social.followees[user]:
                if not self.data.user.has_key(u2):
                    cleanPair.append((user, u2))
        for u in cleanList:
            del self.social.followees[u]

        for pair in cleanPair:
            if self.social.followees.has_key(pair[0]):
                del self.social.followees[pair[0]][pair[1]]

        cleanList = []
        cleanPair = []
        for user in self.social.followers:
            if not self.data.user.has_key(user):
                cleanList.append(user)
            for u2 in self.social.followers[user]:
                if not self.data.user.has_key(u2):
                    cleanPair.append((user, u2))
        for u in cleanList:
            del self.social.followers[u]

        for pair in cleanPair:
            if self.social.followers.has_key(pair[0]):
                del self.social.followers[pair[0]][pair[1]]

        idx = []
        for n, pair in enumerate(self.social.relation):
            if pair[0] not in self.data.user or pair[1] not in self.data.user:
                idx.append(n)

        for item in reversed(idx):
            del self.social.relation[item]

        cleanList = []
        cleanPair = []
        for movie in self.meta.actors:
            if not self.data.item.has_key(movie):
                cleanList.append(movie)
            for actor in self.meta.actors[movie]:
                if not self.meta.actor.has_key(actor):
                    cleanPair.append((movie, actor))
        for m in cleanList:
            del self.meta.actors[m]

        for pair in cleanPair:
            if self.meta.actors.has_key(pair[0]):
                del self.meta.actors[pair[0]][pair[1]]

        cleanList = []
        cleanPair = []
        for actor in self.meta.act:
            if not self.meta.actor.has_key(actor):
                cleanList.append(actor)
            for movie in self.meta.act[actor]:
                if not self.meta.item.has_key(movie):
                    cleanPair.append((actor, movie))
        for a in cleanList:
            del self.meta.act[a]

        for pair in cleanPair:
            if self.meta.act.has_key(pair[0]):
                del self.meta.act[pair[0]][pair[1]]

        idx = []
        for n, pair in enumerate(self.meta.inform1):
            if pair[0] not in self.meta.item or pair[1] not in self.meta.actor:
                idx.append(n)

        for item in reversed(idx):
            del self.meta.inform1[item]

        cleanList = []
        cleanPair = []
        for movie in self.meta.md:
            if not self.data.item.has_key(movie):
                cleanList.append(movie)
            for dire in self.meta.md[movie]:
                if not self.meta.dire.has_key(dire):
                    cleanPair.append((movie, dire))
        for m in cleanList:
            del self.meta.md[m]

        for pair in cleanPair:
            if self.meta.md.has_key(pair[0]):
                del self.meta.md[pair[0]][pair[1]]

        cleanList = []
        cleanPair = []
        for dire in self.meta.dm:
            if not self.meta.dire.has_key(dire):
                cleanList.append(dire)
            for movie in self.meta.dm[dire]:
                if not self.meta.item.has_key(movie):
                    cleanPair.append((dire, movie))
        for d in cleanList:
            del self.meta.dm[d]

        for pair in cleanPair:
            if self.meta.dm.has_key(pair[0]):
                del self.meta.dm[pair[0]][pair[1]]

        idx = []
        for n, pair in enumerate(self.meta.inform2):
            if pair[0] not in self.meta.item or pair[1] not in self.meta.dire:
                idx.append(n)

        for item in reversed(idx):
            del self.meta.inform2[item]