Documentation
¶
Overview ¶
`mkt` package provides marketing-related data analysis functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CAI = CustomerActivityIndex
CAI is an alias for CustomerActivityIndex.
Functions ¶
func CustomerActivityIndex ¶ added in v0.2.5
func CustomerActivityIndex(dt insyra.IDataTable, caiConfig CAIConfig) insyra.IDataTable
CustomerActivityIndex calculates the Customer Activity Index (CAI) for each customer based on their transaction history. It returns a DataTable containing CustomerID, MLE, WMLE, and CAI for each customer.
Parameters:
- dt: Input DataTable containing transaction records.
- caiConfig: Configuration for CAI calculation, including column indices/names and date format.
CAI ¶
CAI (Customer Activity Index) is a metric used to evaluate customer activity based on their transaction history. It tells the change in customer activity level over time. A positive CAI indicates a customer whose activity is increasing, while a negative CAI indicates a customer whose activity is decreasing.
**Only customers with at least 4 transactions are considered for CAI calculation.**
func RFM ¶
func RFM(dt insyra.IDataTable, rfmConfig RFMConfig) insyra.IDataTable
RFM performs RFM analysis on the given data table based on the provided configuration. It returns a new data table containing the R, F, M scores and the combined RFM score for each customer.
Types ¶
type BasketConfig ¶ added in v0.2.18
type BasketConfig struct {
OrderIDColIndex string // The column index(A, B, C, ...) of order ID in the data table
OrderIDColName string // The column name of order ID in the data table (if both index and name are provided, index takes precedence)
ProductIDColIndex string // The column index(A, B, C, ...) of product ID in the data table
ProductIDColName string // The column name of product ID in the data table (if both index and name are provided, index takes precedence)
}
BasketConfig 是 BasketAnalysis 的設定。 輸入資料形式與 RFM / CAI 類似:每一列代表「某張訂單包含的某項商品」。
type BasketResult ¶ added in v0.2.18
type BasketResult struct {
Support insyra.IDataTable // 支援度矩陣: P(A ∩ B) = 同時購買 A 和 B 的訂單數 / 總訂單數
Confidence insyra.IDataTable // 置信度矩陣: P(B | A) = 同時購買 A 和 B 的訂單數 / 購買 A 的訂單數
Lift insyra.IDataTable // 提升度矩陣: Support(A,B) / (P(A) * P(B))
}
BasketResult holds the three matrices returned by BasketAnalysis. 三個矩陣皆為 商品 × 商品 的方陣,列代表前項商品 A、欄代表後項商品 B。
func BasketAnalysis ¶ added in v0.2.18
func BasketAnalysis(dt insyra.IDataTable, config BasketConfig) *BasketResult
BasketAnalysis performs market basket analysis on the given transaction data. It returns a BasketResult containing the support, confidence, and lift matrices, each stored as a DataTable where rows represent the antecedent item A and columns represent the consequent item B.
- Support(A, B) = orders containing both A and B / total orders
- Confidence(A→B) = orders containing both A and B / orders containing A
- Lift(A→B) = Support(A, B) / (P(A) * P(B))
Each order is treated as a set of items, so duplicated product IDs within the same order are counted only once.
type CAIConfig ¶ added in v0.2.5
type CAIConfig struct {
CustomerIDColIndex string // The column index(A, B, C, ...) of customer ID in the data table
CustomerIDColName string // The column name of customer ID in the data table (if both index and name are provided, index takes precedence)
TradingDayColIndex string // The column index(A, B, C, ...) of trading day in the data table
TradingDayColName string // The column name of trading day in the data table (if both index and name are provided, index takes precedence)
DateFormat string // The format of the date string (e.g., "YYYY-MM-DD", "DD/MM/YYYY", "yyyy-mm-dd")
TimeScale TimeScale // The time scale for analysis (e.g., hourly, daily, weekly, monthly, yearly)
}
type RFMConfig ¶
type RFMConfig struct {
CustomerIDColIndex string // The column index(A, B, C, ...) of customer ID in the data table
CustomerIDColName string // The column name of customer ID in the data table (if both index and name are provided, index takes precedence)
TradingDayColIndex string // The column index(A, B, C, ...) of trading day in the data table
TradingDayColName string // The column name of trading day in the data table (if both index and name are provided, index takes precedence)
AmountColIndex string // The column index(A, B, C, ...) of amount in the data table
AmountColName string // The column name of amount in the data table (if both index and name are provided, index takes precedence)
NumGroups uint // The number of groups to divide the customers into
DateFormat string // The format of the date string (e.g., "YYYY-MM-DD", "DD/MM/YYYY", "yyyy-mm-dd")
TimeScale TimeScale // The time scale for analysis (e.g., hourly, daily, weekly, monthly, yearly)
}