Skip to main content

An implementation of kaHFM algorithm

Project description

pykaHFM

Implementace algoritmu kaHFM.

import numpy as np

from pykaHFM import (
    TFIDFTransformer,
    FactorizationMachine,
    StochasticGradientDescent,
    load_knowledge_base_triples,
)

movies = ["Avengers", "Avengers: Infinity War",
          "Stardust", "Princess Bride", "Last Witchhunter", "Tall Girl"]
users = ["Chandler", "Joey", "Ross", "Monica", "Rachel", "Phoebe"]


n_movies = len(movies)
n_users = len(users)

user_movie_matrix = np.random.randint(1, 6, size=(n_users, n_movies))
knowledge_base = [('Avengers', 'genre', 'Teen'),
 ('Avengers', 'genre', 'Thriller'),
 ('Avengers', 'genre', 'Comedy'),
 ('Avengers', 'genre', 'Fantasy'),
 ('Avengers', 'genre', 'Comedy'),
 ('Avengers', 'genre', 'Adult'),
 ('Avengers', 'genre', 'Adult'),
 ('Avengers: Infinity War', 'genre', 'Adult'),
 ('Avengers: Infinity War', 'genre', 'Teen'),
 ('Avengers: Infinity War', 'genre', 'Adventure'),
 ('Avengers: Infinity War', 'genre', 'Thriller'),
 ('Stardust', 'genre', 'Comedy'),
 ('Stardust', 'genre', 'Adventure'),
 ('Stardust', 'genre', 'Drama'),
 ('Stardust', 'genre', 'Adult'),
 ('Stardust', 'genre', 'Comedy'),
 ('Stardust', 'genre', 'Drama'),
 ('Princess Bride', 'genre', 'Adventure'),
 ('Last Witchhunter', 'genre', 'Fantasy'),
 ('Last Witchhunter', 'genre', 'Drama'),
 ('Last Witchhunter', 'genre', 'Action'),
 ('Tall Girl', 'genre', 'Teen'),
 ('Tall Girl', 'genre', 'Adult'),
 ('Tall Girl', 'genre', 'Thriller'),
 ('Tall Girl', 'genre', 'Adventure'),
 ('Tall Girl', 'genre', 'Teen'),
 ('Tall Girl', 'genre', 'Teen'),
 ('Tall Girl', 'genre', 'Drama'),
 ('Tall Girl', 'genre', 'Sci-fi')
 ]

tfidf = TFIDFTransformer(knowledge_base, user_movie_matrix, users, movies)
tfidf.generate_v_matrix()

fm = FactorizationMachine(users, movies, user_movie_matrix, tfidf.v_matrix)

sgd = StochasticGradientDescent(fm, iterations=10, learning_rate=0.0001)
sgd.fit()

Y_hat = fm.predict_all()

print(Y_hat)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pykaHFM-0.2.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

pykaHFM-0.2.2-py2.py3-none-any.whl (5.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pykaHFM-0.2.2.tar.gz.

File metadata

  • Download URL: pykaHFM-0.2.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for pykaHFM-0.2.2.tar.gz
Algorithm Hash digest
SHA256 52031d140cb6aa6dc74768ca7407ce31cf4d7661f26208ec360553e4c2546fc4
MD5 ce012b602e1f0885598b459c100872af
BLAKE2b-256 9273f74d5654081aabe057acabe29200504dcee3d2dac09e0f255d23bc415f80

See more details on using hashes here.

File details

Details for the file pykaHFM-0.2.2-py2.py3-none-any.whl.

File metadata

  • Download URL: pykaHFM-0.2.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for pykaHFM-0.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 614abae25424329c9f965d2d30dbdbb2cc50d4444a485c6111b60209b19a9056
MD5 a0137bde1f03cefb55bca83dab416c69
BLAKE2b-256 f94ab27504ef70cf7a41f5e56cdc348fbb4e2a67717000c7c76e5038b4c781d3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page