Rusket

0.1.90 · active · verified Fri Apr 17

Rusket is an ultra-fast Python library designed for building recommender engines (collaborative filtering) and performing market basket analysis (association rules). It leverages Rust for its core computational logic, offering significant performance advantages, especially with large datasets. The current version is 0.1.90, and it is under active development with a focus on speed and efficiency.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `MarketBasketAnalyzer` to find association rules from a pandas DataFrame of transactional data. It initializes the analyzer, fits it to the data using specified transaction and item columns, and then retrieves the generated rules.

import pandas as pd
from rusket import MarketBasketAnalyzer

# Sample transactional data for Market Basket Analysis
data = {
    'transaction_id': [1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6],
    'item_id': ['Apple', 'Banana', 'Orange', 'Apple', 'Grape', 'Banana', 'Orange', 'Apple', 'Banana', 'Grape', 'Milk', 'Bread', 'Eggs', 'Milk', 'Cheese', 'Butter']
}
df = pd.DataFrame(data)

# Initialize and fit the Market Basket Analyzer
# Lower min_support/min_confidence for small sample data to ensure rules are found
mba = MarketBasketAnalyzer(min_support=0.01, min_confidence=0.01)

mba.fit(df, transaction_col='transaction_id', item_col='item_id')

# Get association rules
rules = mba.get_rules()
print("Generated Association Rules (first 5):")
if not rules.empty:
    print(rules.head())
else:
    print("No rules found. Try adjusting min_support or min_confidence.")

view raw JSON →