Skip to main content

AIFuzzyRec

A Python library for generating AI-powered item recommendations using fuzzy logic and SQLite databases. AIFuzzyRec leverages fuzzy set theory and artificial intelligence to compute item similarities based on user-item interactions, providing flexible and AI-enhanced recommendations for applications like e-commerce, content platforms, or personalized systems.

Features

  • Fuzzy Logic-Based Recommendations: Uses fuzzy membership functions to compute item similarities, allowing nuanced recommendation scores.

  • Flexible Database Schema: Supports any SQLite database with user-item interaction data, with customizable table and column names.

  • Context Manager Support: Ensures automatic cleanup of database connections using Python's with statement.

  • Configurable Fuzzy Weights: Adjust weights for low, medium, and high similarity to fine-tune recommendation behavior.

  • Error Handling: Robust handling of invalid user/item IDs and empty databases.

  • Logging: Optional logging of recommendations to a file for debugging and analysis.

  • Easy Integration: Lightweight and compatible with Python 3.6+.

Installation

Install AIFuzzyRec using pip:

pip install ai-fuzzy-rec

Or, if using Poetry, add it to your project:

poetry add ai-fuzzy-rec

Requirements

Python >= 3.6 pandas >= 2.0.0 scikit-fuzzy >= 0.4.2 numpy >= 1.25.0 scipy >= 1.10.0 packaging >= 21.3

Usage

Basic Example

Generate recommendations using a SQLite database (purchases.db) containing user-item interactions:

from ai_fuzzy_rec import FuzzyRecommender

# Initialize with default settings
with FuzzyRecommender(db_path='purchases.db') as recommender:
    # Recommend items similar to item ID 2
    item_rec = recommender.recommend_items_for_item(2, top_n=3)
    print(f"Items recommended for item 2: {[(item, round(score, 3)) for item, score in item_rec]}")

    # Recommend items for user ID 1
    user_rec = recommender.recommend_items_for_user(1, top_n=3)
    print(f"Items recommended for user 1: {[(item, round(score, 3)) for item, score in user_rec]}")

Expected Output:

Items recommended for item 2: [(3, 0.5), (4, 0.5), (1, 0.5)]
Items recommended for user 1: [(4, 1.0), (5, 0.5)]

Custom Schema and Parameters

Use a custom database schema and adjust fuzzy weights:

from ai_fuzzy_rec import FuzzyRecommender

with FuzzyRecommender(
    db_path='custom.db',
    table_name='orders',
    user_col='customer_id',
    item_col='product_id',
    fuzzy_weights=(0.1, 0.4, 0.5),  # Emphasize high similarity
    log_file='custom_recommendations.log'
) as recommender:
    item_rec = recommender.recommend_items_for_item(2, top_n=2)
    print(f"Top 2 items for item 2: {item_rec}")

Database Setup

Create a SQLite database with user-item interactions:

import sqlite3

# Create a sample database
conn = sqlite3.connect('purchases.db')
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS purchases
                 (user_id INTEGER, item_id INTEGER)''')
# Insert sample data
data = [(1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (2, 4),
        (3, 3), (3, 4), (3, 5), (4, 1), (4, 4), (5, 1), (5, 2)]
cursor.executemany('INSERT INTO purchases VALUES (?, ?)', data)
conn.commit()
conn.close()

Testing

Run tests to verify functionality:

poetry run pytest

This executes tests in tests/test_ai_fuzzy_rec.py, ensuring recommendations and error handling work as expected.

Project Structure

/home/m/pyprj/
├── ai_fuzzy_rec/
│   ├── __init__.py
│   ├── ai_fuzzy_rec.py
├── create_database.py
├── purchases.db
├── pyproject.toml
├── README.md
├── LICENSE
├── test_recommender.py
└── tests/
    └── test_ai_fuzzy_rec.py

Metadata

Release files for ai-fuzzy-rec 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ai-fuzzy-rec 0.1.0
File Size Uploaded Provenance
ai_fuzzy_rec-0.1.0.tar.gz 5.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ai-fuzzy-rec 0.1.0
File Interpreter ABI Platform
ai_fuzzy_rec-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.5 kB

Release files / ai_fuzzy_rec-0.1.0.tar.gz

Download URL ai_fuzzy_rec-0.1.0.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7992a4399de8cd1205901cd5c3fbe910c7e3ec1f546c343381f9303606ba8786
BLAKE2b-256 checksum
How to use checksums
2a775045383c3b835590c71d506dea27741c78aba13d1beb53750d3b6928ac1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.11.2 Linux/6.1.0-35-amd64

Release files / ai_fuzzy_rec-0.1.0-py3-none-any.whl

Download URL ai_fuzzy_rec-0.1.0-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
51e5adc61635a51d5b4dbfbc6320349ac69cfd03e9c3d92d509b0e0e2d4bb0ad
BLAKE2b-256 checksum
How to use checksums
833f542e244ef33eb5357b1d77c7cabce456d9c1e66bb629b320b7406a4370bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.11.2 Linux/6.1.0-35-amd64

Security for ai-fuzzy-rec 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page