
โ๏ธ Co-visitation Matrix ๊ณต๋ถ์ ํจ๊ป ๋ค๋ฅธ ๋ฐฉ๋ฒ๋ก ๊ณต๋ถ๋ฅผ ํด์ ์ ๋ฆฌํ๊ธฐ๋ก ํ๋ค. ์ฆ๊ฑฐ์ด ๋๋ฅด๋ง๋ฌด~ ๋ด์ผ ์ ๋
์ ์์ ํ์ ์ค๋น๋ฅผ ์ํด ์ค๋์ ์ง์์

๋์๋ฐ์ ๊ทธ๋ฃนํ(co-occurence grouping)๋ ๊ฐ์ฒด ๊ฐ์ ์ฐ๊ด์ฑ์ ์ฐพ์๋ด๋ ๋ฐ์ดํฐ ๋ง์ด๋ ๊ธฐ๋ฒ์ด๋ค. ๋์๋ฐ์ ๊ทธ๋ฃนํ๋ ์์ดํ A๊ฐ ๋ฐ์ํ๋ฉด ์์ดํ B๋ ๋ฐ์ํ ๊ฐ๋ฅ์ฑ์ด ์๋ค๋ ๊ท์น์ด ์ผ๋ฐ์ ์ด๋ค.
๋์๋ฐ์ ํ๋ ฌ์ ์์ดํ
๊ฐ์ ๋์๋ฐ์ ํ์๋ฅผ ํ๋ ฌ๋ก ๋ํ๋ธ ๊ฒ์ผ๋ก, ๋ ์์ดํ
์ด ๋์์ ๋ฐ์ํ ํ์๊ฐ ๋ง์์๋ก ๋ ๋ง์ ๊ด๋ จ์ด ์๊ฑฐ๋ ์ ์ฌํ๋ค๋ ๊ฐ๋
์ด๋ค. ์๋ ๊ทธ๋ฆผ์ ๋์๋ฐ์ ํ๋ ฌ๊ณผ ์ฌ์ฉ์ ์ ํธ ๊ฐ์ ์ด์ฉํ์ฌ ์ถ์ฒ ๋ฒกํฐ์ธ R์ ๊ณ์ฐํ๋ ๋ฐฉ๋ฒ์ ๋ํด์ ๋ํ๋๋ค.

์ ๊ทธ๋ฆผ์ 7๊ฐ ์์ดํ
์ ๋ํ ๋์๋ฐ์ ํ๋ ฌ๋ก 7 x 7 ํ๋ ฌ๋ก ๊ตฌ์ฑ๋๋ค. ๊ฐ ํ์ ํน์ ์์ดํ
๊ณผ ๋ค๋ฅธ ๋ชจ๋ ์์ดํ
๊ฐ์ ๋์ ๋ฐ์ํ์์ด๋ฉฐ, ์์ดํ
A์ ์์ดํ
B์ ๋์๋ฐ์ ํ์์ ์์ดํ
B์ ์์ดํ
A์์ ๋์๋ฐ์ ํ์๋ ๋์ผํ๊ธฐ ๋๋ฌธ์ ์ข์ฐ๋์นญ์ด๋ค. ์ถ์ฒ ๋ฒกํฐ R์ ๊ฐ ํ๊ณผ ์ฌ์ฉ์์ ์ ํธ๋ฒกํฐ์ ๋ด์ ์ ํตํด์ ๊ณ์ฐ๋๋ค. ์ฌ์ฉ์์ ์์ดํ
6์ ๋ํ R์ ๊ณ์ฐํ ์๋ ์๋ค.

์ฌ์ฉ์๋ ์์ดํ
1, 2, 5, 7์ ๋ํ ์ ํธ๋ฅผ ๋ํ๋๋ค. ๋ฐ๋ผ์ ์ถ์ฒ์ ์์ดํ
3, 4, 5์ ๋ํด์ ์ด๋ฃจ์ด์ ธ์ผ ํ๋ฏ๋ก, ๊ฐ์ฅ ์ข์ ์ถ์ฒ์ ์์ดํ
6์ด ๋๋ค. ์ด์ ๊ฐ์ด ํน์ ์์ดํ
์ด ์ฌ์ฉ์๊ฐ ์ ํธ๋ฅผ ํ์ํ ๋ค๋ฅธ ์์ดํ
๊ณผ ๋์์ ๋ฐ์ํ๊ฑฐ๋ ํน์ ์์ดํ
์ ๋์๋ฐ์์ด ์ ํธ๊ฐ ํฐ ์์ดํ
๊ณผ ๋ง์ด ๊ฒน์น๋ค๋ฉด R์ ๊ฐ์ ์ปค์ง๊ฒ ๋๋ค.

- Co-occurrence grouping (also known as frequent itemset mining, association rule discovery, and market-basket analysis) attempts to find associations between entities based on transactions involving them.
- An example co-occurrence question would be: What items are commonly purchased together?
- While clustering looks at similarity between objects based on the objectsโ attributes, co-occurrence grouping considers similarity of objects based on their appearing together in transactions.
- For example, analyzing purchase records from a supermarket may uncover that ground meat is purchased together with hot sauce much more frequently than we might expect.
- Deciding how to act upon this discovery might require some creativity, but it could suggest a special promotion, product display, or combination offer.
- Co-occurrence of products in purchases is a common type of grouping known as market-basket analysis. Some recommendation systems also perform a type of affinity grouping by finding, for example, pairs of books that are purchased frequently by the same people (โpeople who bought X also bought Yโ).
- The result of co-occurrence grouping is a description of items that occur together. These descriptions usually include statistics on the frequency of the co-occurrence and an estimate of how surprising it is.
๊ฒฐ๊ตญ Co-Visitaion Matrix = Co-Occurence Matrix = ARD ๋ผ๋ ๊ฒ์ด๋ค. ๊ฒฐ๊ตญ ๋ด๊ฐ ์๊ณ ์๋ ์ฐ๊ด ๋ถ์์ด Co-visitation์ด์๋ ๊ฒ์ด๋ค. ์๋ง์ง์ฐฝํธ ๊ทธ๋ ๋๋์ฒด ๋ช ์ ์์ ๋ด๋ค๋ณธ ๊ฒ์ธ์ง... ์ด์ Kaggle์ ์๋ Code๋ฅผ ์ข ๋ฏ์ด๋ณด๋ฉด์ ์ฝ๋๋ฅผ ์ดํดํด๋ณด๋ ๋จ๊ณ๋ฅผ ๊ฑฐ์ณ์ผ ํ ๊ฒ ๊ฐ๋ค.
fraction_of_sessions_to_use = 1
if fraction_of_sessions_to_use != 1:
lucky_sessions_train = df.drop_duplicates(['session']).sample(frac=fraction_of_sessions_to_use, random_state=42)['session']
subset_of_train = df[df.session.isin(lucky_sessions_train)]
else:
subset_of_train = df
subset_of_train.index = pd.MultiIndex.from_frame(subset_of_train[['session']])
chunk_size = 30_000
min_ts = df.ts.min()
max_ts = df.ts.max()
from collections import defaultdict, Counter
next_AIDs = defaultdict(Counter)
sessions = df.session.unique()
df=df.drop(['Unnamed: 0'],axis=1)
์ฌ๊ธฐ๊น์ง ์คํํ๊ณ ๋๋ฉด df๋ ๋ค์๊ณผ ๊ฐ์ ํํ๊ฐ ๋๋ค.

์ด์ ๊ฐ์ฅ ์ค์ํ ์ด ์ฝ๋๋ฅผ ์ ์ดํดํ๋ฉด ๋๋ค.
import datetime as dt
# 0๋ถํฐ session row ๊ฐ์ -1๊น์ง, ์ฆ session row ๊ฐ์๊น์ง๋ฅผ chunk_size๋งํผ ๊ฑด๋๋ฐ๋ฉฐ ๋ฐ๋ณต๋ฌธ์ ๋๋ค.
# chunk_size = 30000๊ฐ์ฉ ๋์ด๊ฐ๋ฉด์. i=0, 30000, 60000, ...
for i in range(0, sessions.shape[0], chunk_size):
# ํ์ฌ chunk = i๋ฒ์งธ event ๋ถํฐ chunk ํฌ๊ธฐ ๋งํผ๊น์ง์ ํ์ ๊ฐ์ ธ์จ๋ค.
# min์ ๊ณ์ฐํ๋ ๊ณผ์ ์ ๋งจ ๋ง์ง๋ง์ chunk_size๋ณด๋ค ๋จ์ ๋ฐ์ดํฐ๊ฐ ์ ์ ๋๋ฅผ ์ํจ.
# sessions.shape[0]-1 : sessions ์ด ๊ฐ์. ์ฆ range์ ๋ ๋ฒ์์ ๋๋ฌํ์ ๋.
# i+chunk_size-1 : ๋ค์ chunk๊น์ง์ ๊ธธ์ด. general case.
current_chunk = df.loc[sessions[i]:sessions[min(sessions.shape[0]-1, i+chunk_size-1)]].reset_index(drop=True)
# session ๊ธฐ์ค์ผ๋ก groupbyํ๊ณ ๋์ ๊ฐ์ session๋ผ๋ฆฌ ๋ฌถ์ธ ๊ทธ๋ฃน ์์์
# nth : Take the nth row from each group if n is an int, otherwise a subset of rows.
# : n๋ฒ์งธ ํ์ ๊ฐ์ ธ์จ๋ค. => -30๋ฒ์งธ ํ๋ถํฐ -1๋ฒ์งธ ํ๊น์ง ๊ฐ์ ธ์จ๋ค.
# session์ ๋๋ถ๋ถ์ ๊ฐ์ ธ์จ๋ค. -> ์์๋ถ๋ถ๋ณด๋ค ๋๋ถ๋ถ์ด ๋ ์ข์ ํ๋ฅ ์ด ๋๋ค
current_chunk = current_chunk.groupby('session', as_index=False).nth(list(range(-30,0))).reset_index(drop=True)
# session ์ด์ ๊ธฐ์ค์ผ๋ก ์๊ธฐ ์์ ์ inner join(๊ต์งํฉ)ํ๋ค.
consecutive_AIDs = current_chunk.merge(current_chunk, on='session')
# ๊ฐ์ aid๊ฐ ์ค๋ณต๋ ๊ฒฝ์ฐ๋ฅผ ๋บธ๋ค.
consecutive_AIDs = consecutive_AIDs[consecutive_AIDs.aid_x != consecutive_AIDs.aid_y]
# str์ ts์ด์ datetime type์ผ๋ก ๋ฐ๊ฟ์ค๋ค.
consecutive_AIDs.ts_y=pd.to_datetime(consecutive_AIDs.ts_y)
consecutive_AIDs.ts_x=pd.to_datetime(consecutive_AIDs.ts_x)
# y์ x์ ์๊ฐ ์ฐจ์ด๋ฅผ ๊ตฌํ๋ค.
time_diff=(consecutive_AIDs.ts_y - consecutive_AIDs.ts_x)
# ์๊ฐ ์ฐจ์ด๋ฅผ consecutive_AIDS์ ์ด๋ก ์ถ๊ฐํ๋ค.
consecutive_AIDs['days_elapsed'] = time_diff
# ์๊ฐ ์ฐจ์ด๊ฐ ํ๋ฃจ ์ดํ์ธ ๋ ๋ง ์ถ์ถํด์ ์ ์ฅํ๋ค.
consecutive_AIDs = consecutive_AIDs[(consecutive_AIDs.days_elapsed >= dt.timedelta(days=0)) & (consecutive_AIDs.days_elapsed <= dt.timedelta(days=1))]
for aid_x, aid_y in zip(consecutive_AIDs['aid_x'], consecutive_AIDs['aid_y']):
next_AIDs[aid_x][aid_y] += 1
์คํํ๊ณ ๋์ consecutive_AIDS๋ ๋ค์๊ณผ ๊ฐ์ด ์๊ฒผ๋ค.

์คํํ๊ณ ๋์ next_AIDS๋ "collections.defaultdict" type์ผ๋ก ์๋์ ๊ฐ์ด ์๊ฒผ๋ค. aid_x์ ๋ํด์(์ฆ ๋ชจ๋ aid_x์ ๋ํด์) ์ค๋ณต๋์ง ์๋ ์ ํ์ธ aid_y๊ฐ ๋์์ count๋ ํ์๋ฅผ ์ธ๋ ๊ฒ ๊ฐ๋ค.

๐ Chunk
Chunk : ๋ฐ์ดํฐ ๋ฉ์ด๋ฆฌ๋ก ์์ ํ ๋ ๊ฐ ์ปค๋ฐ ์ฌ์ด์ ์ฒ๋ฆฌ๋๋ row ์
Chunk ์งํฅ ์ฒ๋ฆฌ : ํ ๋ฒ์ ํ๋์ฉ ๋ฐ์ดํฐ๋ฅผ ์ฝ์ด Chunk๋ผ๋ ๋ฉ์ด๋ฆฌ๋ฅผ ๋ง๋ ๋ค, Chunk ๋จ์๋ก transactions์ ๋ค๋ฃจ๋ ๊ฒ
chunk_size : ํ ๋ฒ์ ์ฒ๋ฆฌ๋ transaction ๋จ์
์ฆ, ๋ค์ ๋จ๊ณ๋ฅผ ๊ฑฐ์น๊ฒ ๋๋ค.
- Reader์์ ๋ฐ์ดํฐ๋ฅผ ํ๋ ์ฝ์ด์จ๋ค.
- ์ฝ์ด์จ ๋ฐ์ดํฐ๋ฅผ Processor์์ ๊ฐ๊ณตํ๋ค.
- ๊ฐ๊ณต๋ ๋ฐ์ดํฐ๋ค์ ๋ณ๋์ ๊ณต๊ฐ์ ๋ชจ์ ๋ค, Chunk ๋จ์๋งํผ ์์ด๊ฒ ๋๋ฉด Writer์ ์ ๋ฌํ๊ณ Writer๋ ์ผ๊ด ์ ์ฅํ๋ค.
๐ range()
range ํจ์์ ์ธ ๋ฒ์งธ ํ๋ผ๋ฏธํฐ๋ step์ ์๋ฏธํ๋ค. ์์ ์ธ๋ฑ์ค๋ถํฐ ์ผ๋ง์ฉ ๊ฑด๋๋ฐ๋ฉฐ ์ดํ์ง๋ฅผ ๋ณด๋ ๊ฒ์ด๋ค. ์๋ ๊ทธ๋ฆผ์ ๋ณด๋ฉด ์ดํด๊ฐ ์ฝ๋ค.
- step: [optional] integer value, denoting the difference between any two numbers in the sequence.
๐ pandas - merge
merge ๋ฉ์๋ ๋ ๋ ๋ฐ์ดํฐํ๋ ์์ ๊ฐ ๋ฐ์ดํฐ์ ์กด์ฌํ๋ ๊ณ ์ ๊ฐ(key)์ ๊ธฐ์ค์ผ๋ก ๋ณํฉํ ๋ ์ฌ์ฉํ๋ค.
- default : DataFrame.merge(right, how='inner', on=None, left_on=None, right_on=None, left_index=False, right_index=False, sort=False, suffixes=('_x', '_y'), copy=True, indicator=False, validate=None
- right : ์ค๋ฅธ์ชฝ ๋ฐ์ดํฐํ๋ ์
- left_on : ๊ธฐ์ค์ด ์ด๋ฆ์ด ๋ค๋ฅผ ๋, ์ผ์ชฝ ๊ธฐ์ค์ด
- right_on : ๊ธฐ์ค์ด ์ด๋ฆ์ด ๋ค๋ฅผ ๋, ์ค๋ฅธ์ชฝ ๊ธฐ์ค์ด
- left_index / right_index : ์ธ๋ฑ์ค ๊ธฐ์ค ๋ณํฉ ์ True๋ก ํ๋ฉด ํด๋น ๊ฐ์ฒด์ ์ธ๋ฑ์ค๊ฐ ๋ณํฉ ๊ธฐ์ค์ด ๋๋ค.
- on : (๋ ๋ฐ์ดํฐํ๋ ์์ ๊ธฐ์ค์ด ์ด๋ฆ์ด ๊ฐ์ ๋) ๊ธฐ์ค์ด
- how : ์กฐ์ธ ๋ฐฉ์ {'left', 'right', 'inner', 'outer'} ๊ธฐ๋ณธ๊ฐ์ 'inner'
- sort : ๋ณํฉ ํ ์ธ๋ฑ์ค์ ์ฌ์ ์ ์ ๋ ฌ ์ฌ๋ถ
- suffixes : ๋ณํฉํ ๊ฐ์ฒด๋ค๊ฐ ์ด๋ฆ์ด ์ค๋ณต๋๋ ์ด์ด ์๋ค๋ฉด, ํด๋น ์ด์ ๋ถ์ผ ์ ๋ฏธ์ฌ
- copy : ์ฌ๋ณธ์ ์์ฑํ ์ง ์ฌ๋ถ
- indicator : True๋ก ํ ๊ฒฝ์ฐ ๋ณํฉ์ด ์๋ฃ๋ ๊ฐ์ฒด์ ์ถ๊ฐ๋ก ์ด์ ํ๋ ์์ฑํ์ฌ ๋ณํฉ ์ ๋ณด๋ฅผ ์ถ๋ ฅ
- validate : {'1:1' / '1:m' / 'm:1' / 'm:m'} ๋ณํฉ ๋ฐฉ์์ ๋ง๋์ง ํ์ธํ ์ ์๋ค. ๋ง์ฝ validate์ ์ ๋ ฅํ ๋ณํฉ๋ฐฉ์๊ณผ, ์ค์ ๋ณํฉ ๋ฐฉ์์ด ๋ค๋ฅผ๊ฒฝ์ฐ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค
- ๊ฐ๋จํ๊ฒ ๋ฐ์ดํฐ์ ๊ณผ ๋น์ทํ dataframe์ ๋ง๋ค๊ณ ํ ์คํธ ํด๋ณด์๋ค.
๐ nth
๋์ถฉ ์ด๋ ๊ฒ ์๊ธด DataFrame์ด ์๋ค๊ณ ๊ฐ์ ํ์.
(1) nth์ range๋ฅผ (-1,0)์ผ๋ก ์ค์ : -1
(2) nth์ range๋ฅผ (-2,0)์ผ๋ก ์ค์ : -2 -1
(3) nth์ range๋ฅผ (-3,0)์ผ๋ก ์ค์ : -3 -2 -1
- ๊ฒฐ๋ก : ๊ฐ์ session๋ผ๋ฆฌ groupby๋ ๊ทธ๋ฃน ๊ฐ๊ฐ์์ 'list์์ ๋ค์ด์๋ ๊ฐ'๋ฒ์งธ ํ๋ ฌ์ ๊ฐ์ ธ์จ๋ค.
์ด์ test set ์ทจ๊ธ์ ํ๋ df3์ ์ ์ฉํด๋ณด๊ธฐ๋ก ํ๋ค.
del df
test=pd.read_csv("/content/drive/MyDrive/khuda_recosys_kaggle/df_sample3.csv")
session_types = ['clicks', 'carts', 'orders']
test_session_AIDs = test.reset_index(drop=True).groupby('session')['aid'].apply(list)
test_session_types = test.reset_index(drop=True).groupby('session')['type'].apply(list)

labels=[]
no_data = 0
no_data_all_aids = 0
type_weight_multipliers = {0: 1, 1: 6, 2: 3}
for AIDs, types in zip(test_session_AIDs, test_session_types):
# ๋ง์ฝ test_session_AIDS์ AID๊ฐ 20๊ฐ ์ด์์ธ ๊ฒฝ์ฐ
if len(AIDs) >= 20:
# 0.1๋ถํฐ 1๊น์ง๋ฅผ AIDS ๊ฐ์๋งํผ ์ชผ๊ฐ ๋ค. ๊ทธ๋ฆฌ๊ณ ์ด ๊ฐ์์ 1์ ๋บด์ ๊ฐ์ค์น ๋ฆฌ์คํธ๋ฅผ ๊ตฌํ๋ค.
# ์ test_session_AIDS์ AIDs์ ํด๋นํ๋ ๋ฆฌ์คํธ ์์์ ์ธ๋ฑ์ค๊ฐ ํด์๋ก ๊ฐ์ค์น๊ฐ ํด๊น.
# ๊ธธ์ด๋ ์ด๋ค ์๋ฏธ์ผ๊น.
# ๋ฆฌ์คํธ๊ฐ ์ด๋ป๊ฒ ์ ๋ ฌ๋์ด์๋ ํํ์ธ๊ฐ? = ?
weights=np.logspace(0.1,1,len(AIDs),base=2, endpoint=True)-1
# ๋น์ด์๋ defaultdict ์์ฑ
aids_temp=defaultdict(lambda: 0)
# w =
# type_weight_multipliers[t] : type(click, cart, order)์ ๋ฐ๋ฅธ ๊ฐ์ค์น. hyperparam
for aid,w,t in zip(AIDs,weights,types):
aids_temp[aid]+= w * type_weight_multipliers[t]
# aids_temp์์ ์ ๋ ฌ์ ํ ๋ค์์ aid number๋ง ๋ฝ๋๋ค.
sorted_aids=[k for k, v in sorted(aids_temp.items(), key=lambda item: -item[1])]
# top 20๊ฐ๋ง ๋ฝ๋๋ค.
labels.append(sorted_aids[:20])
# ๋ง์ฝ test_session_AIDS์ AID๊ฐ 20๊ฐ๋ณด๋ค ์ ๊ฒ ์๋ ๊ฒฝ์ฐ
else:
# AIDS[::-1] ์ฒ์๋ถํฐ ๋๊น์ง ์ญ์์ผ๋ก ( ๋->์ฒ์ )
AIDs = list(dict.fromkeys(AIDs[::-1]))
#
AIDs_len_start = len(AIDs)
# ํ๋ณด๊ตฐ ๋ด์ ๋น ์งํฉ์ ๋ง๋ ๋ค.
candidates = []
# test์ ์๋ aid์ ๋ํ์ฌ for๋ฌธ ์คํ
for AID in AIDs:
# ๋ง์ฝ aid๊ฐ next_AIDs์ ๋ค์ด์๋ค๋ฉด, ํ๋ณด๊ตฐ ๋ฆฌ์คํธ์ ํด๋น aid์ next_AIDs์์
# ์ ์ผ ๋ง์ด Count ๋์๋ aid top20๊ฐ๋ฅผ ๋ฃ๋๋ค.
if AID in next_AIDs: candidates += [aid for aid, count in next_AIDs[AID].most_common(20)]
# ์์ฑ๋ ํ๋ณด๊ตฐ ์งํฉ์ Top40์ aid number๋ฅผ ๊ฐ์ ธ์ค๊ณ
# ์ด Top40์์ ์ด๋ฏธ AIDs์ ๋ค์ด๊ฐ aid number์ ์ ์ธํ๋ค.
AIDs += [AID for AID, cnt in Counter(candidates).most_common(40) if AID not in AIDs]
# AIDS ๋ฆฌ์คํธ์์ top 20๋ง ์ ์ ํ์ฌ labels์ ๋ด๋๋ค.
labels.append(AIDs[:20])
# ๋ฐ์ดํฐ ์๋ ๊ฒฝ์ฐ(ํ๋ณด๊ตฐ ๋ฆฌ์คํธ๊ฐ ๋น์ด์๋ ๊ฒฝ์ฐ๊ฐ ๋๋ค.)
if candidates == []: no_data += 1
#
if AIDs_len_start == len(AIDs): no_data_all_aids += 1
๐ numpy.logspace
numpy.logspace(start, stop, num, endpoint, base, dtype)
logspace๋ ์ค์ ํ ๋ฒ์์์ ๋ก๊ทธ๋ก ๋ถํ ํ ์์น์ ๊ฐ์ ์ถ๋ ฅํ๋ค.
- start - ์์ ๊ฐ
- stop - ๊ฐ์ ๋ง์ง๋ง ๊ฐ. ๋จ, endpoint๊ฐ True์ด๋ฉด ํฌํจ๋๊ณ , False์ด๋ฉด ํฌํจ๋์ง ์๋๋ค.
- num - ๋ฐฐ์ด ๋งด๋ฒ์ ๊ฐ์์ ๋๋ค. default=50
- endpoint - stop ๊ฐ์ ํฌํจ ์ฌ๋ถ๋ฅผ ํ์ธํ๋ ๊ฒ์ ๋๋ค. True - ํฌํจ, Fasle -๋ฏธํฌํจ
- base - Log ๊ฐ์ ๋ฒ ์ด์ค ๊ฐ์ ๋๋ค. default=10
- dtype - ๋ฐฐ์ด์ ๋ฐ์ดํฐ ํ์
- ์์
๐ Counter( ) , most_commons( ) module
- collections.Counter(a) : a์์ ์์๋ค์ ๊ฐ์๋ฅผ ์ธ์ด, ๋์ ๋๋ฆฌ ํํ๋ก ๋ฐํํฉ๋๋ค. {๋ฌธ์ : ๊ฐ์} ํํ
- most_common() ํจ์ - ์ต๋น๊ฐ ๊ตฌํ๊ธฐ
collections.Counter(a).most_common(n) : a์ ์์๋ฅผ ์ธ์ด, ์ต๋น๊ฐ n๊ฐ๋ฅผ ๋ฐํํฉ๋๋ค. (๋ฆฌ์คํธ์ ๋ด๊ธด ํํํํ๋ก)
labels_as_strings = [' '.join([str(l) for l in lls]) for lls in labels]
predictions = pd.DataFrame(data={'session_type': test_session_AIDs.index, 'labels': labels_as_strings})

labels_as_strings = [' '.join([str(l) for l in lls]) for lls in labels]
predictions = pd.DataFrame(data={'session_type': test_session_AIDs.index, 'labels': labels_as_strings})
prediction_dfs = []
for st in session_types:
modified_predictions = predictions.copy()
modified_predictions.session_type = modified_predictions.session_type.astype('str') + f'_{st}'
prediction_dfs.append(modified_predictions)
submission = pd.concat(prediction_dfs).reset_index(drop=True)

์ฐธ๊ณ ์๋ฃ
https://data-analysis-expertise.tistory.com/92
https://www.geeksforgeeks.org/python-range-function/
https://appia.tistory.com/154