Final Score Analyzer

得到评论的标准评分。

用法

根据评论分数分布得到商品最终标准评分

生成评论评分器实例

brands = ['vivo', 'oppo', 'mi', 'huawei', 'apple', 'SMARTISAN']
from taobao_crawler.analyzer.final_score_analyzer import FinalScoreAnalyzer
score_analyzer = FinalScoreAnalyzer(db)
score_analyzer.set_brand(brands)

FinalScoreAnalyzer(db) 中的 db 参见 DB

查询某一商品分数分布

item_id = ''
score_analyzer.score_distribution_run(item_id)

查询某一商品标准分数

item_id = ''
score_analyzer.score_distribution_run(item_id)

保存三种评分两两散点图

score_analyzer.compared_score_run()

保存各品牌最终评分图

final_scores = self.three_score_to_final_score(self.three_scores, [0.43, 0.25, 0.32])
self.draw_final_score(final_scores)

类属性

class analyzer.final_score_analyzer.FinalScoreAnalyzer(db, brand_name=('vivo', 'oppo', 'mi', 'huawei', 'apple', 'SMARTISAN'))

Bases: object

利用商品的评论信息,通过三种中间评分,得到一种对于商品的好评评分

__init__(db, brand_name=('vivo', 'oppo', 'mi', 'huawei', 'apple', 'SMARTISAN'))
参数:
  • db – 一个 pymongo.MongoClient.db 的实例
  • brand_name – 所研究的所有品牌名
brand_to_id(brand)

通过品牌名得到其下商品

参数:brand – list, 所研究的所有品牌名
返回:iteration, 遍历该品牌下所有商品(dictionary)的iteration
draw_final_score(final_score)

画散点图

参数:final_score – list(shape=(m,n), m为品牌数,n为评论数)
draw_scatter(x, y, title, write_file_address)

画散点图

参数:
  • x – 横轴
  • y – 纵轴
  • title – 图片标题
  • write_file_address – 图片保存地址
id_to_each_score(item_id)

通过商品ID得到其评论情感评分

参数:item_id – string, 商品ID
返回:list, 该ID商品所有评论的情感评分
run()

运行函数 保存三种评分两两散点图与各品牌最终评分图

score_to_three_score(score, fractile_parameter, good_comment_parameter)

根据一种评分得到三个评分

参数:
  • score – 原始评分分数
  • fractile_parameter – 分位数参数, (0,1)
  • good_comment_parameter – 好评比例参数, (0,1)
返回:

list(平均数-分位数-好评比例)

set_brand(brand_name)

更改品牌名称

参数:brand_name – list, 品牌名称
three_score_to_final_score(scores, weight)

根据三种评分得到最终评分

参数:
  • scores – 三种评分
  • weight – 三种评分权重
返回:

list(最终评分)