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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

推荐系统中多值特征的八大处理技巧

發(fā)布時(shí)間:2025/3/8 windows 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 推荐系统中多值特征的八大处理技巧 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在諸多數(shù)據(jù)處理的問題中,存在著一類特殊的特征--多值特征,該類特征常見的情形有:

  • 論文的關(guān)鍵字描述信息;
  • 商品信息的描述;
  • 網(wǎng)站關(guān)鍵詞;
  • 其它情況;

那么關(guān)于這些多值特征,該如何處理,都有哪些常見操作呢?本文我們介紹多值特征的8大處理技能,希望對(duì)大家有所啟發(fā)和幫助。

  • Count
  • LabelEncoder
  • Multi One-Hot
  • CounterVector
  • TfidfVectorizer
  • Word2Vec
  • 基礎(chǔ)Multi-Value Embedding
  • 加權(quán)Multi-Value Embedding
  • 此處我們介紹幾種最為常見的多值特征的處理技巧。

    即計(jì)算多值特征中有多少個(gè)值。

    如果特征存在明顯的聚集效應(yīng),很多多值特征組合在一起就是一個(gè)有意義的信息,例如,

    • 文章關(guān)鍵詞里面的:SVM|監(jiān)督學(xué)習(xí);
    • 商品里面的,女生|連衣裙;

    等等,這些詞組合在一起就是很有意義的一類信息,可以直接LabelEncoder進(jìn)行編碼;

    這個(gè)不用多說了,就是每個(gè)不同的值對(duì)應(yīng)一列特征,出現(xiàn)了就是1沒出現(xiàn)就是0。

    CounterVector是One-Hot的擴(kuò)展,統(tǒng)計(jì)了每個(gè)詞在當(dāng)前文本下的出現(xiàn)次數(shù),如果每個(gè)關(guān)鍵詞在當(dāng)前的Multi-Value特征中都是唯一的值的時(shí)候,那么CounterVector就和One-Hot等價(jià)。

    TfidfVectorizer又可以認(rèn)為是CounterVector的擴(kuò)展,它還考慮了在上下問中文本的出現(xiàn)次數(shù)。

    先使用Word2Vec進(jìn)行訓(xùn)練,得到每個(gè)詞的詞向量,再基于詞向量做統(tǒng)計(jì)特征。

    對(duì)多值每個(gè)值進(jìn)行emebdding之后,然后取對(duì)應(yīng)的統(tǒng)計(jì)值進(jìn)行concat得到最終的Multi-Value的表示。

    和基礎(chǔ)的直接取均值最大最小值等統(tǒng)計(jì)特征不一樣,此處我們自動(dòng)學(xué)習(xí)每個(gè)embedding對(duì)應(yīng)的權(quán)重,然后再進(jìn)行加權(quán)得到最終的emebdding。

    當(dāng)然上面是最基礎(chǔ)的一種加權(quán)策略,還有很多其它的策略,例如SENet等等。

    此處我們就列舉下面幾種常見的操作,

    • LabelEncoder
    • CountVectorizer(包含Multi One-Hot)
    • TfidfVectorizer
    • Word2Vec

    其余的有興趣的大家可以自己嘗試。

    from sklearn.preprocessing import LabelEncoder corpus = ['This is the first document.','This document is the second document.','And this is the third one.','Is this the first document?',]vectorizer = LabelEncoder() X = vectorizer.fit_transform(corpus) X

    array([3, 2, 0, 1])

    02 CountVectorizer

    • Multi One-Hot是CountVectorizer的特例,此處就不再贅述。
    from sklearn.feature_extraction.text import CountVectorizer corpus = ['This is the first document.','This document is the second document.','And this is the third one.','Is this the first document?',]vectorizer = CountVectorizer() X = vectorizer.fit_transform(corpus) X

    <4x9 sparse matrix of type '<class 'numpy.int64'>' with 21 stored elements in Compressed Sparse Row format>

    03 TfidfVectorizer

    from sklearn.feature_extraction.text import TfidfVectorizer corpus = ['This is the first document.','This document is the second document.','And this is the third one.','Is this the first document?',]vectorizer = TfidfVectorizer() X = vectorizer.fit_transform(corpus) X

    <4x9 sparse matrix of type '<class 'numpy.float64'>'
    with 21 stored elements in Compressed Sparse Row format>

    04 Word2Vec

    import numpy as np import pandas as pd from gensim import modelsdef to_text_vector(txt, model):'''將文本txt轉(zhuǎn)化為文本向量'''words = txt.split(',') array = np.asarray([model.wv[w] for w in words if w in words],dtype='float32') return array.mean(axis=0)## 案例 sentences = ["1,2,3",'3,4,1','1,4,2'] model = models.Word2Vec(sentences, workers=8, min_count = 1, vector_size = 10, window = 2) to_text_vector(txt="1,2,3", model= model)

    array([-0.03244876, 0.00847926, -0.01252694, -0.0171898 , -0.02409677, -0.01349981, 0.01097592, 0.01558573, -0.01085999, -0.0165647 ], dtype=float32)

    本文我們針對(duì)常見的多值特征問題,介紹了8大通用的處理策略。當(dāng)然在多值特征等處理時(shí),還需要注意:

    • 如果多值特征和其它基于時(shí)間戳的特征等一起出現(xiàn)還需要特別注意很多衍生特征;
    • 如果有多個(gè)關(guān)聯(lián)的多值特征出現(xiàn)的時(shí)候的一些衍生特征;

    推薦系統(tǒng)中多值特征的八大處理技巧!

    總結(jié)

    以上是生活随笔為你收集整理的推荐系统中多值特征的八大处理技巧的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。