国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

kaggle學(xué)習(xí)筆記-otto-baseline10-實(shí)現(xiàn)拉狄克簡單共訪矩陣極坐標(biāo)

這篇具有很好參考價(jià)值的文章主要介紹了kaggle學(xué)習(xí)筆記-otto-baseline10-實(shí)現(xiàn)拉狄克簡單共訪矩陣極坐標(biāo)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

DEBUG = False
!pip install polars
!pip install snoop
from collections import defaultdict, Counter
import gc
from snoop import pp
import polars as pl
import pandas as pd
import numpy as np
import random
from polars.testing import assert_frame_equal, assert_series_equal
from datetime import datetime

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
pd.set_option('display.max_colwidth', None)
cfg = pl.Config.restore_defaults()  
pl.Config.set_tbl_rows(50)  
pl.Config.set_fmt_str_lengths(1000)
if DEBUG: fraction_of_sessions_to_use = 0.00001
else: fraction_of_sessions_to_use = 1
train_ms = pl.scan_parquet('/kaggle/input/otto-radek-style-polars/train_ms.parquet')
test_ms = pl.scan_parquet('/kaggle/input/otto-radek-style-polars/test_ms.parquet')
sample_sub = pl.scan_csv('/kaggle/input/otto-recommender-system/sample_submission.csv')

子集訓(xùn)練和測(cè)試并將它們連接在一起

%%time
lucky_sessions_train = (
    train_ms
    .select([
        pl.col('session').unique().sample(frac=fraction_of_sessions_to_use, seed=42)
    ])
    .collect()
    .to_series().to_list()
)

lucky_sessions_test = (
    test_ms
    .select([
        pl.col('session').unique().sample(frac=fraction_of_sessions_to_use, seed=42)
    ])
    .collect()
    .to_series().to_list()
)


subset_of_train = (
    train_ms
    .filter(pl.col('session').is_in(lucky_sessions_train))

)

subset_of_test = (
    test_ms
    .filter(pl.col('session').is_in(lucky_sessions_test))

)

subsets = pl.concat([subset_of_train, subset_of_test]).collect()
sessions = subsets.select('session').unique().to_series().to_list()
pp(lucky_sessions_train[:3], len(lucky_sessions_train), lucky_sessions_test[:3], len(lucky_sessions_test),
   subset_of_train.collect().height, subset_of_test.collect().height, subsets.height)

創(chuàng)建共同訪問矩陣
共同訪問矩陣只是探索以下想法/問題的名稱
一個(gè)輔助設(shè)備/產(chǎn)品與同一會(huì)話中或所有會(huì)話中的其他輔助設(shè)備/產(chǎn)品之間是否存在任何關(guān)系?
是否有一些輔助工具與某些輔助工具更相似,而與其他輔助工具更不同?
當(dāng)查看此輔助工具時(shí),是否有可能,某些輔助工具比其他輔助工具更有可能被點(diǎn)擊/購物車/訂購?
我們能否為每個(gè)會(huì)話將輔助工具配對(duì)在一起并計(jì)算配對(duì)的次數(shù)?
由于一個(gè)輔助(例如,“122”)可以有許多配對(duì)伙伴,通過計(jì)算配對(duì)(“122”,配對(duì)伙伴)的出現(xiàn)次數(shù),我們能否找到援助“122”最常見的配對(duì)伙伴?
下一次點(diǎn)擊、購物車或訂單可能是測(cè)試會(huì)話的最后一次輔助(或所有輔助)最常見的配對(duì)伙伴嗎?
建立共同訪問矩陣的第一個(gè)挑戰(zhàn)是如何配對(duì)
在拉狄克的筆記本中,配對(duì)邏輯如下

僅使用每個(gè)會(huì)話的最后 30 個(gè)輔助工具相互配對(duì)
刪除相同伙伴的對(duì)
保留一天內(nèi)右伴侶在左伴侶之后的配對(duì)
我們可以調(diào)整配對(duì)邏輯來改變我們的共同訪問矩陣

%%time 
next_AIDs = defaultdict(Counter)
chunk_size = 300000
for i in range(0, len(sessions), chunk_size):
    current_chunk = (
        subsets
        .filter(pl.col('session').is_between(sessions[i], sessions[np.min([i+chunk_size-1, len(sessions)-1])], closed='both'))
        .unique() # no duplicates
        .groupby('session').tail(30)
    )
    current_chunk = (
        current_chunk
        .join(current_chunk, on='session', suffix='_right')
        .sort(['session', 'aid', 'aid_right']) # nice view
        .filter(pl.col('aid') != pl.col('aid_right')) # no need for pairs of themselves
        .with_columns([
            ((pl.col('ts_right') - pl.col('ts'))/(24*60*60*1000)).alias('days_elapsed') # differentiate aid_right is after or before aid in days
        ])
        .filter((pl.col('days_elapsed')>=0) & (pl.col('days_elapsed') <=1)) # only pairs whose aid_rights are after aid within 24 hrs
    )

    # defaultdict + Counter is super faster than pure polars solution
    for aid_x, aid_y in zip(current_chunk.select('aid').to_series().to_list(), current_chunk.select('aid_right').to_series().to_list()):
        next_AIDs[aid_x][aid_y] += 1

    print(f'{int(np.ceil(i/chunk_size))} out of {int(np.ceil(len(sessions)/chunk_size))} - {np.min([i+chunk_size-1, len(sessions)-1])} sessions are done')
len(next_AIDs)

polars版本和pandas版本差不多,在這里看拉狄克的速度

del train_ms, subset_of_train, subsets
gc.collect()

使用共同訪問矩陣在測(cè)試會(huì)話中輔助人員少于 20 人時(shí)提供幫助候選人
拉狄克在這里向我們展示了兩件事:

如何創(chuàng)建特征(基于時(shí)間、類型和出現(xiàn)的權(quán)重)以在測(cè)試會(huì)話中選擇 20 個(gè)輔助工具
如何從共同訪問矩陣中選擇候選人?
在測(cè)試會(huì)話中為每種輔助工具選取 20 種最常見的輔助工具,并將它們放入候選列表中
從候選列表中選擇 40 種最常見的輔助工具,如果它們是新參加會(huì)話的,請(qǐng)將它們添加到測(cè)試會(huì)話的輔助工具中
然后選擇前 20 個(gè)輔助工具

%%time
lists_aids_types = (
    test_ms
    .unique() #
    .groupby('session')
    .agg([
        pl.col('aid').list().alias('test_session_AIDs'),
        pl.col('type').list().alias('test_session_types'),        
    ])
    .collect()
)

lists_aids_types.head()

%%time
labels = []
session_types = ['clicks', 'carts', 'orders']
no_data = 0
no_data_all_aids = 0
type_weight_multipliers = {0: 1, 1: 6, 2: 3}
test_session_AIDs = lists_aids_types.select('test_session_AIDs').to_series().to_list()
test_session_types = lists_aids_types.select('test_session_types').to_series().to_list()

# take each session's aids and types
for AIDs, types in zip(test_session_AIDs, test_session_types):

    # if the session has more than 20 aids
    if len(AIDs) >= 20: 
        # np.logspace: Return numbers spaced evenly on a log scale.
        # `-1` is to ensure the weights ranges between [0,1]
        # the weights is given to AIDs based on the time order or chronological order
        weights=np.logspace(start=0.1,stop=1,num=len(AIDs),base=2, endpoint=True)-1 
        
        # create a defaultdict for this session only
        # anything added into this dict will have a default value 0
        # try `aids_temp[1]` and `aids_temp`
        aids_temp=defaultdict(lambda: 0)
        
        # in each sess, an aid may occur multiples in multiple types at different time, 
        # the line below is to take all 3 factors into account to value the importance of this aid to the session
        # each unique aid and its aggregated weight are stored in a defaultdict
        for aid,w,t in zip(AIDs,weights,types): 
            aids_temp[aid]+= w * type_weight_multipliers[t]
          
        # let's 
        sorted_aids=[k for k, v in sorted(aids_temp.items(), key=lambda item: -item[1])]

        # when using the polars below to replace the line above, it is actually 2 times slower
        # aid = [key for (key, value) in aids_temp.items()]
        # adwt = [value for (key, value) in aids_temp.items()]
        # sorted_aids = (
        #     pl.DataFrame([aid, adwt], columns=['aid', 'weight'])
        #     .sort('weight', reverse=True)
        #     .select('aid').to_series().to_list()
        # )

        # take the 20 aids with the largest weights from this session as one list and append it into a new list `labels`
        labels.append(sorted_aids[:20])
    
    # when this session has less than 20 aids
    else:
        # reverse the order of AIDs (a list of aids of this session) and remove the duplicated aids
        AIDs = list(dict.fromkeys(AIDs[::-1])) # python version
        
        # If using this polars below to replace the line above, it is infinitely slower
        # AIDs = pl.Series('aid', AIDs).unique().reverse().to_list() # polars version

        # keep track of the length of new AIDs above
        AIDs_len_start = len(AIDs)
        

        candidates = []
        # take each unique aid of this session, access its the 20 most common pair-partners and their counts
        # insert the list of the 20 most common pair-partner aids into another list `candidates` (only a pure list )
        # in the end, this `candidates` list is a lot and has many duplicates too
        for AID in AIDs:
            if AID in next_AIDs: candidates += [aid for aid, count in next_AIDs[AID].most_common(20)]
                
        # take the 40 most common aids from `candidates`, and if they are already inside AIDs of this session, 
        # then insert them into AIDs (still a pure list because of `+`, and `append` can't do it)
        AIDs += [AID for AID, cnt in Counter(candidates).most_common(40) if AID not in AIDs]
        
        # but we still only take the first 20 aids from AIDs as this session's prediction and store it in `labels`
        labels.append(AIDs[:20])
        
        # if no candidates are generated, count 1 to `no_data`
        # if candidates == []: no_data += 1 # this variable is actually not used by Radek
        
        # keep an account of the num of aids in this session and all sessions which adding no candidates
        if AIDs_len_start == len(AIDs): no_data_all_aids += 1
sample_sub.fetch().head()

創(chuàng)建提交標(biāo)簽文章來源地址http://www.zghlxwxcb.cn/news/detail-400243.html

%%time
(
    pl.DataFrame({'session': lists_aids_types.select('session').to_series().to_list(), 
                  'labels': labels})
    .with_columns([
        pl.col('labels').arr.eval(pl.element().cast(pl.Utf8)).arr.join(' '),
        (pl.col('session')+"_clicks").alias('clicks'),
        (pl.col('session')+"_carts").alias('carts'),
        (pl.col('session')+"_orders").alias('orders'),        
    ])
    .select([
        'session',
        pl.concat_list(['clicks', 'carts', 'orders']).alias('session_type'),
        'labels'
    ])
    .explode('session_type')
    .sort('session')
    .select(pl.exclude('session'))
    .write_csv('submission.csv')
)
print(f'Test sessions that we did not manage to extend based on the co-visitation matrix: {no_data_all_aids}')
pl.read_csv('submission.csv').shape
sample_sub.collect().shape
# from matplotlib import pyplot as plt

# plt.hist([len(l) for l in labels]);
# plt.suptitle('Distribution of predicted sequence lengths');

到了這里,關(guān)于kaggle學(xué)習(xí)筆記-otto-baseline10-實(shí)現(xiàn)拉狄克簡單共訪矩陣極坐標(biāo)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • AI量化模型預(yù)測(cè)——baseline學(xué)習(xí)筆記

    1. 賽題名稱 ????????AI量化模型預(yù)測(cè) 2. 賽題理解 ????????本賽事是一個(gè)量化金融挑戰(zhàn),旨在通過大數(shù)據(jù)與機(jī)器學(xué)習(xí)的方法,使用給定的訓(xùn)練集和測(cè)試集數(shù)據(jù),預(yù)測(cè)未來中間價(jià)的移動(dòng)方向。參賽者需要理解市場行為的原理,創(chuàng)建量化策略,并利用過去不超過100個(gè)數(shù)據(jù)點(diǎn)的

    2024年02月14日
    瀏覽(17)
  • kaggle學(xué)習(xí)筆記-情感和地理空間分析

    kaggle學(xué)習(xí)筆記-情感和地理空間分析

    秘魯食品評(píng)論中的情緒和地理空間分析 自然語言處理 (NLP) 是人工智能的一個(gè)分支,致力于讓計(jì)算機(jī)能夠像人類一樣理解文本和口語單詞。 另一方面,地理空間分析是對(duì)圖像、GPS、衛(wèi)星攝影和歷史數(shù)據(jù)的收集、顯示和操作,這些數(shù)據(jù)以地理坐標(biāo)明確描述,或以街道地址、郵政

    2024年02月16日
    瀏覽(19)
  • 第十二屆“中國軟件杯”大賽:A10-基于機(jī)器學(xué)習(xí)的分布式系統(tǒng)故障診斷系統(tǒng)——baseline(一)

    第十二屆“中國軟件杯”大賽:A10-基于機(jī)器學(xué)習(xí)的分布式系統(tǒng)故障診斷系統(tǒng)——baseline(一)

    在分布式系統(tǒng)中某個(gè)節(jié)點(diǎn)發(fā)生故障時(shí),故障會(huì)沿著分布式系統(tǒng)的拓?fù)浣Y(jié)構(gòu)進(jìn)行傳播,造成自身節(jié)點(diǎn)及其鄰接節(jié)點(diǎn)相關(guān)的KPI指標(biāo)和發(fā)生大量日志異常。本次比賽提供分布式數(shù)據(jù)庫的故障特征數(shù)據(jù)和標(biāo)簽數(shù)據(jù),其中特征數(shù)據(jù)是系統(tǒng)發(fā)生故障時(shí)的KPI指標(biāo)數(shù)據(jù),KPI指標(biāo)包括由feature0、

    2024年02月11日
    瀏覽(21)
  • 深度學(xué)習(xí)筆記(kaggle課程《Intro to Deep Learning》)

    深度學(xué)習(xí)筆記(kaggle課程《Intro to Deep Learning》)

    深度學(xué)習(xí)是一種機(jī)器學(xué)習(xí)方法,通過構(gòu)建和訓(xùn)練深層神經(jīng)網(wǎng)絡(luò)來處理和理解數(shù)據(jù)。它模仿人腦神經(jīng)系統(tǒng)的工作方式,通過多層次的神經(jīng)網(wǎng)絡(luò)結(jié)構(gòu)來學(xué)習(xí)和提取數(shù)據(jù)的特征。深度學(xué)習(xí)在圖像識(shí)別、語音識(shí)別、自然語言處理等領(lǐng)域取得了重大突破,并被廣泛應(yīng)用于人工智能技術(shù)中

    2024年02月13日
    瀏覽(25)
  • AI繪畫基于 Kaggle 10 分鐘搭建 Stable Diffusion(保姆級(jí)教程)

    AI繪畫基于 Kaggle 10 分鐘搭建 Stable Diffusion(保姆級(jí)教程)

    當(dāng)前最火的、也是日常繪畫最常用兩個(gè) AI 繪畫工具就屬 Midjourney 和 Stable Diffusion 了。 而相對(duì)于 Midjourney(基礎(chǔ)版也要 $10 / month)來說,Stable Diffusion 最大的好處就是: 完全免費(fèi)! (免費(fèi)啊,寶子們) 完全開源! 但是 Stable Diffusion 的 安裝部署比較復(fù)雜 ,而且 對(duì)電腦配置要求

    2024年02月11日
    瀏覽(96)
  • 機(jī)器學(xué)習(xí)數(shù)據(jù)集:Kaggle

    Kaggle成立于2010年,是一個(gè)進(jìn)行數(shù)據(jù)發(fā)掘和預(yù)測(cè)競賽的在線平臺(tái)。從公司的角度來講,可以提供一些數(shù)據(jù),進(jìn)而提出一個(gè)實(shí)際需要解決的問題;從參賽者的角度來講,他們將組隊(duì)參與項(xiàng)目,針對(duì)其中一個(gè)問題提出解決方案,最終由公司選出的最佳方案可以獲得5K-10K美金的獎(jiǎng)金。

    2024年02月08日
    瀏覽(14)
  • AI繪畫StableDiffusion:云端在線版使用筆記分享(Kaggle版)

    AI繪畫StableDiffusion:云端在線版使用筆記分享(Kaggle版)

    玩AI繪畫(SD),自己電腦配置不夠?今天給大家介紹一下如何baipiao在線版AI繪畫StableDiffusion。 Kaggle 是世界上最大的數(shù)據(jù)科學(xué)社區(qū),擁有強(qiáng)大的工具和資源,可幫助您實(shí)現(xiàn)數(shù)據(jù)科學(xué)目標(biāo)。(每周可以免費(fèi)使用30個(gè)小時(shí))。 打開如下鏈接,復(fù)制并編輯后,創(chuàng)建你自己的代碼 ht

    2024年02月15日
    瀏覽(16)
  • 李宏毅機(jī)器學(xué)習(xí) hw2 boss baseline 解析

    李宏毅機(jī)器學(xué)習(xí) hw2 boss baseline 解析

    Multiclass Classification ,讓你判斷給定的向量是屬于哪一個(gè) phoneme ,由于一個(gè) phoneme 可能包含好多個(gè)向量,所以要對(duì)數(shù)據(jù)進(jìn)行處理,對(duì)向量進(jìn)行拼接。 不同baseline 要求 先給出我最終使用的過boss baseline的方法,后面再介紹我一步步的思考過程。 助教提示過boss baseline要使用RNN模型

    2023年04月09日
    瀏覽(75)
  • 李宏毅機(jī)器學(xué)習(xí) hw7 boss baseline分享

    李宏毅機(jī)器學(xué)習(xí) hw7 boss baseline分享

    使用bert來做問答任務(wù) 答案是都是可以在 Document 找到的,輸入 Document 和 Query 輸出兩個(gè)數(shù)字分別表示答案在Document中的開始和結(jié)束位置。 輸入格式如下: doc stride ,初始時(shí) Doc stride 等于 max_paragraph_len ,這樣會(huì)導(dǎo)致在測(cè)試時(shí)如果答案在邊界附近就會(huì)被切割到兩個(gè)不同的 window 中

    2024年02月06日
    瀏覽(17)
  • 李宏毅 2022機(jī)器學(xué)習(xí) HW2 strong baseline 上分路線

    李宏毅 2022機(jī)器學(xué)習(xí) HW2 strong baseline 上分路線

    baseline 增加concat_nframes (提升明顯) 增加batchnormalization 和 dropout 增加hidden layer寬度至512 (提升明顯) 提交文件命名規(guī)則為 prediction_{concat_nframes} [{n_hidden_layers} {dropout}_bn].csv (2%) Implement 2 models with approximately the same number of parameters, (A) one narrower and deeper (e.g. hidden_layers=6, hidden

    2024年02月10日
    瀏覽(21)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包