Models
rankmc.model.markovchain
create_mc_df(x, df_index)
creates a dataframe with the probability of each product to generate a rank dataframe
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
ndarray
|
steady state probabilities of the markov chain |
required |
df_index |
DataFrame
|
dataframe with the index and the id |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: ranked dataframe of the products based on markov chain probabilities |
Source code in src/rankmc/model/markovchain.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
create_sparse_matrix(df, df_index)
Create a sparse matrix from the dataframe
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
prepared dataframe for the sparse matrix construction |
required |
df_index |
DataFrame
|
prepared dataframe with the index and the id |
required |
Returns:
Type | Description |
---|---|
tuple[csr_matrix, ndarray]
|
sp.sparse.csr_matrix: sparse matrix with the data |
Source code in src/rankmc/model/markovchain.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
init_state_mc(df, n)
generate the initial state for the markov chain based on the number of ids from the dataframe
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
prepared dataframe |
required |
n |
int
|
number of ids from id table |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: initial state for the markov chain |
Source code in src/rankmc/model/markovchain.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
prepare_df_for_sparse_matrix(df, col_id, col_shift, df_index)
Prepare the dataframe for the sparse matrix construction applying equal weights to all transitions within the same product combination
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
dataframe with the data with groups and ids columns |
required |
col_id |
str
|
column name of the group |
required |
col_shift |
str
|
column name of the id shifted |
required |
df_index |
DataFrame
|
the dataframe with the index and the id |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: dataframe with the data ready for the sparse matrix construction |
Source code in src/rankmc/model/markovchain.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|