日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python surprise

發布時間:2023/12/8 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python surprise 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

surprise 庫


目錄

  • surprise 庫
      • 目錄
      • 參考文檔
      • 安裝
      • 預測算法
      • prediction_algorithms包
      • The algorithm base class 算法基類
      • Baselines estimates configuration 基線法估計配置
      • 使用GridSearchCV調整算法參數
      • Similarity measure configuration 相似度度量配置
      • Trainset class
    • 源碼解讀
      • reader 類
      • dataset 類
      • trainset 類
      • KNNBaseline 類
      • KNNBasic 類
      • example
      • split 數據分割
        • ShuffleSplit 類

參考文檔

Surprise’ documentation
GitHub — Surprise

安裝

With pip (you’ll need numpy, and a C compiler. Windows users might prefer using conda):

$ pip install numpy $ pip install scikit-surprise

With conda:

$ conda install -c conda-forge scikit-surprise

For the latest version, you can also clone the repo and build the source (you’ll first need Cython and numpy):

$ pip install numpy cython $ git clone https://github.com/NicolasHug/surprise.git $ cd surprise $ python setup.py install

預測算法

  • 所有算法都由AlgoBase基類生成,基類里實現了一些關鍵的方法,(e.g. predict, fit and test).
  • Every algorithm is part of the global Surprise namespace, so you only need to import their names from the Surprise package
    任何算法都是在surprise庫的全局命名空間中,可以直接調用。
  • prediction_algorithms包

    算法類名說明解釋
    random_pred.NormalPredictorAlgorithm predicting a random rating based on the distribution of the training set, which is assumed to be normal.根據訓練集的分布特征隨機給出一個預測值
    baseline_only.BaselineOnlyAlgorithm predicting the baseline estimate for given user and item.給定用戶和Item,給出基于baseline的估計值
    knns.KNNBasicA basic collaborative filtering algorithm.最基礎的協作過濾
    knns.KNNWithMeansA basic collaborative filtering algorithm, taking into account the mean ratings of each user.將每個用戶評分的均值考慮在內的協作過濾實現
    knns.KNNBaselineA basic collaborative filtering algorithm taking into account a baseline rating.考慮基線評級的協作過濾
    matrix_factorization.SVDThe famous SVD algorithm, as popularized by Simon Funk during the Netflix Prize.SVD實現
    matrix_factorization.SVDppThe SVD++ algorithm, an extension of SVD taking into account implicit ratings.SVD++,即LFM+SVD
    matrix_factorization.NMFA collaborative filtering algorithm based on Non-negative Matrix Factorization.基于矩陣分解的協作過濾
    slope_one.SlopeOneA simple yet accurate collaborative filtering algorithm.一個簡單但精確的協作過濾算法
    co_clustering.CoClusteringA collaborative filtering algorithm based on co-clustering.基于協同聚類的協同過濾算法

    The algorithm base class 算法基類

    The surprise.prediction_algorithms.algo_base module defines the base class AlgoBase from which every single prediction algorithm has to inherit.

  • fit(trainset)

    Train an algorithm on a given training set.
    This method is called by every derived class as the first basic step for training an algorithm. It basically just initializes some internal structures and set the self.trainset attribute.
    Parameters: trainset (Trainset) – A training set, as returned by the folds method.
    Returns: self

    在一個給定的數據集上訓練一個算法

  • Baselines estimates configuration 基線法估計配置

    中用到最小化平方誤差函數的算法(包括Baseline 方法 和相似度計算)都需要配置參數,不同的參數會導致算法有不同的性能,且不同的 baseline 用于不同的算法,參數配置不一樣。
    使用默認的baseline參數已經可以取得一定的性能的。
    需要注意的是,一些相似度度量用到Baseline,無論實際的預測算法是否用到baseline,都需要配置相關參數
    具體的參數配置,可以參考這篇論文
    Factor in the Neighbors: Scalable and Accurate Collaborative Filtering

    使用GridSearchCV調整算法參數

    cross_validate()函數針對給定的一組參數報告交叉驗證過程的準確性度量。 如果你想知道哪個參數組合可以產生最好的結果,那么GridSearchCV類就可以解決問題。 給定一個參數的字典,這個類徹底地嘗試所有參數組合,并報告任何準確性度量(在不同分割上的平均值)的最佳參數。 它受到scikit-learn的GridSearchCV的啟發。

    Similarity measure configuration 相似度度量配置

    Many algorithms use a similarity measure to estimate a rating. The way they can be configured is done in a similar fashion as for baseline ratings: you just need to pass a sim_options argument at the creation of an algorithm. This argument is a dictionary with the following (all optional) keys:

    通過指定sim_options這個字典變量來配置相似度指標
    1. name: 指定相似度指標的名字,similarities module 中給出了MSD
    2. user_based: 指定是使用計算用戶之間的相似度還是Item之間的相似度,這個地方的選擇對預測算法的性能有巨大影響,默認值:True
    3. min_support:當相似度不為0時,最小公共用戶數或公共項目數
    4. shrinkage: 收縮參數,僅用于 pearson_baseline 相似度

    Trainset class

    It is used by the fit() method of every prediction algorithm. You should not try to built such an object on your own but rather use the Dataset.folds() method or the DatasetAutoFolds.build_full_trainset() method.

    訓練集不應該由個人創建,可以通過Dataset.folds()或者DatasetAutoFolds.build_full_trainset()方法創建。

    源碼解讀

    reader 類

    def __init__(self, name=None, line_format='user item rating',sep=None,rating_scale=(1, 5), skip_lines=0):

    建立閱讀器的格式,自動將評分定在rating_scale區間
    self.offset : self.offset = -lower_bound + 1 if lower_bound <= 0 else 0

    def parse_line(self, line)'''Parse a line.Ratings are translated so that they are all strictly positive.Args:line(str): The line to parseReturns:tuple: User id, item id, rating and timestamp. The timestamp is set to ``None`` if it does no exist.'''

    解析一行,返回需要的格式數據

    dataset 類

    def build_full_trainset(self):"""Do not split the dataset into folds and just return a trainset asis, built from the whole dataset.User can then query for predictions, as shown in the :ref:`User Guide<train_on_whole_trainset>`.Returns:The :class:`Trainset <surprise.Trainset>`."""

    將所有數據用于生成訓練集

    def construct_trainset(self, raw_trainset):建立 `raw_id` 到 `inner_id`的映射 得到 ur 字典 --- `用戶-評分`字典ir 字典 --- `Item-評分`字典n_users --- 用戶數n_items --- Item數n_ratings --- 評分記錄數建立訓練集

    trainset 類

    KNNBaseline 類

  • KNNBaseline

    考慮基礎評分的協同過濾
    最好用 pearson_baseline 相似度
    關于Baseline方法的作用,可以參考這篇文章
    推薦系統的協同過濾算法實現和淺析 pdf
  • KNNBasic 類

    def fit(self, trainset):"""計算相似度計算公式的由來可以參考相關書籍""" def estimate(self, u, i):"""估計用戶u對物品i的打分找出在給物品i打過分的k個近鄰用戶根據相應的預測評分計算公式計算預測評分返回值: est, details({'actual_k': actual_k})"""

    example

    庫中,是預測所有用戶沒有評論過的物品的評分
    不適合做Top-N推薦

    split 數據分割

    數據分割部分的分割操作都是針對所有數據集的操作,適合評分預測的應用,不適合Top-N推薦的應用(有待驗證)

    ShuffleSplit 類


    將所有的訓練數據隨機地分成k份。


    將數據分割為訓練集和測試集割為訓練集和測試集

    總結

    以上是生活随笔為你收集整理的python surprise的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 国产对白自拍 | 正在播放亚洲 | 激情网络| 懂色av成人一区二区三区 | 最近中文字幕在线免费观看 | 岛国av网站 | 国产成年网站 | 国产精品视频全国免费观看 | 一级在线免费观看 | 澳门黄色| 97超碰在线播放 | 欧美日韩黑人 | 天天爽夜夜爽夜夜爽精品视频 | 高清国产mv在线观看 | 在线观看亚洲精品 | 成人精品视频一区二区三区尤物 | 国产视频第一页 | 久久一级黄色片 | 91国产精品 | 欧美1| 日日夜夜免费精品 | 青娱乐av在线 | 免费看黄色一级片 | 欧美性69 | 美女福利视频在线 | 91欧美一区二区 | 日韩欧美视频免费在线观看 | 中文字幕无码人妻少妇免费 | av动漫天堂 | 黄色生活毛片 | 98国产精品| 中文字幕1区2区3区 www.com黄色片 | 红桃视频一区二区三区免费 | 色噜噜狠狠一区二区三区果冻 | 日韩av中文字幕在线 | 台湾佬成人中文网222vvv | 日韩av不卡一区 | 国产午夜成人久久无码一区二区 | 免费处女在线破视频 | 欧美日韩人妻精品一区二区三区 | 黄色日批 | 人与动物毛片 | 麻豆av一区二区三区在线观看 | 美女网站在线 | 国产精品交换 | 四虎在线视频 | 欧美aa| 欧美日韩综合网 | 成人理论视频 | 久久久久久久久久久久久久 | 亚洲视频一二三四 | 国产亚洲精品一区二区三区 | 精品国产二区三区 | 亚洲精品在线视频观看 | 夜夜干天天操 | 蜜臀久久99精品久久一区二区 | 韩国一级淫一片免费放 | 免费中文字幕 | 婷婷网址 | 日本xxxx高清 | 2021狠狠操 | 精品一性一色一乱农村 | 免费看女生裸体视频 | 青青草香蕉 | 欧美有码视频 | 真人毛片97级无遮挡精品 | 日女人免费视频 | 久久久久久久久久久网 | 日韩网站在线 | 五月天黄色小说 | 欧美射射射 | 免费在线成人av | 精品一区在线视频 | 清清草在线视频 | 日韩欧美电影一区二区三区 | 影视av | 性欧美又大又长又硬 | 天天视频色| 请用你的手指扰乱我吧 | 精品人妻一区二区三 | 绿帽h啪肉np辣文 | 日日躁夜夜躁白天躁晚上躁91 | 成年人一级黄色片 | 日本国产欧美 | av在线男人天堂 | 日韩女优在线观看 | 波多野结衣一本 | 久久这里只有精品8 | 国产97色在线 | 日韩 | 成人午夜视频精品一区 | 99精品自拍 | 在线免费黄色av | 精品一区二区在线播放 | 在线香蕉视频 | 久草中文网 | h片网站在线观看 | 亚洲激情在线观看视频 | 欧美日韩高清丝袜 | 人人91|