Sparse Matrix Recommender package based on SSparseMatrix objects.
Project description
Sparse Matrix Recommender (SMR) Python package
Introduction
This Python package, SparseMatrixRecommender
, has different functions for computations of recommendations
based on (user) profile or history using Sparse Linear Algebra (SLA). The package mirrors
the Mathematica implementation [AAp1].
(There is also a corresponding implementation in R; see [AAp2]).
The package is based on a certain "standard" Information retrieval paradigm -- it utilizes Latent Semantic Indexing (LSI) functions like IDF, TF-IDF, etc. Hence, the package also has document-term matrix creation functions and LSI application functions. I included them in the package since I wanted to minimize the external package dependencies.
The package includes two data-sets dfTitanic
and dfMushroom
in order to make easier the
writing of introductory examples and unit tests.
For more theoretical description see the article "Mapping Sparse Matrix Recommender to Streams Blending Recommender" , [AA1].
For detailed examples see the files "SMR-experiments-large-data.py" and "SMR-creation-from-long-form.py".
The list of features and its implementation status is given in the org-mode file "SparseMatrixRecommender-work-plan.org".
Workflows
Here is a diagram that encompasses the workflows this package supports (or will support):
Here is a diagram of typical pipeline building using a SparseMatrixRecommender
object:
Installation
To install from GitHub use the shell command:
python -m pip install git+https://github.com/antononcube/Python-packages.git#egg=SparseMatrixRecommender\&subdirectory=SparseMatrixRecommender
To install from PyPI:
python -m pip install SparseMatrixRecommender
Related Python packages
This package is based on the Python package
SSparseMatrix
,
[AAp5].
The package LatentSemanticAnalyzer, [AAp6], uses the cross tabulation and LSI functions of this package.
Usage example
Here is an example of an SMR pipeline for creation of a recommender over Titanic data and recommendations for the profile "passengerSex:male" and "passengerClass:1st":
from SparseMatrixRecommender.SparseMatrixRecommender import *
from SparseMatrixRecommender.DataLoaders import *
dfTitanic = load_titanic_data_frame()
smrObj = (SparseMatrixRecommender()
.create_from_wide_form(data = dfTitanic,
item_column_name="id",
columns=None,
add_tag_types_to_column_names=True,
tag_value_separator=":")
.apply_term_weight_functions(global_weight_func = "IDF",
local_weight_func = "None",
normalizer_func = "Cosine")
.recommend_by_profile(profile=["passengerSex:male", "passengerClass:1st"],
nrecs=12)
.join_across(data=dfTitanic, on="id")
.echo_value())
Remark: More examples can be found the directory "./examples".
Related Mathematica packages
The software monad Mathematica package "MonadicSparseMatrixRecommender.m" [AAp1], provides recommendation pipelines similar to the pipelines create with this package.
here is a Mathematica monadic pipeline for creation of a recommender over Titanic data and recommendations for the profile "male" and "1st':
smrObj =
SMRMonUnit[]⟹
SMRMonCreate[dfTitanic, "id",
"AddTagTypesToColumnNames" -> True,
"TagValueSeparator" -> ":"]⟹
SMRMonApplyTermWeightFunctions["IDF", "None", "Cosine"]⟹
SMRMonRecommendByProfile[{"passengerSex:male", "passengerClass:1st"}, 12]⟹
SMRMonJoinAcross[dfTitanic, "id"]⟹
SMRMonEchoValue[];
(Compare the pipeline diagram above with the corresponding diagram using Mathematica notation .)
Related R packages
The package
SMRMon-R
,
[AAp2], implements a software monad for SMR workflows.
Most of SMRMon-R
functions delegate to SparseMatrixRecommender
.
The package
SparseMatrixRecommenderInterfaces
,
[AAp3], provides functions for interactive
Shiny
interfaces for the recommenders made with SparseMatrixRecommender
and/or SMRMon-R
.
The package
LSAMon-R
,
[AAp4], can be used to make matrices for SparseMatrixRecommender
and/or SMRMon-R
.
Here is the SMRMon-R
pipeline that corresponds to the Python pipeline above:
smrObj <-
SMRMonCreate( data = dfTitanic,
itemColumnName = "id",
addTagTypesToColumnNamesQ = TRUE,
sep = ":") %>%
SMRMonApplyTermWeightFunctions(globalWeightFunction = "IDF",
localWeightFunction = "None",
normalizerFunction = "Cosine") %>%
SMRMonRecommendByProfile( profile = c("passengerSex:male", "passengerClass:1st"),
nrecs = 12) %>%
SMRMonJoinAcross( data = dfTitanic, by = "id") %>%
SMRMonEchoValue
References
Articles
[AA1] Anton Antonov, "Mapping Sparse Matrix Recommender to Streams Blending Recommender" (2017), MathematicaForPrediction at GitHub.
Mathematica and R Packages
[AAp1] Anton Antonov, Monadic Sparse Matrix Recommender Mathematica package, (2018), MathematicaForPrediction at GitHub.
[AAp2] Anton Antonov, Sparse Matrix Recommender Monad in R (2019), R-packages at GitHub/antononcube.
[AAp3] Anton Antonov, Sparse Matrix Recommender framework interface functions (2019), R-packages at GitHub/antononcube.
[AAp4] Anton Antonov, Latent Semantic Analysis Monad in R (2019), R-packages at GitHub/antononcube.
Python packages
[AAp5] Anton Antonov, SSparseMatrix package in Python (2021), Python-packages at GitHub/antononcube.
[AAp6] Anton Antonov, LatentSemanticAnalyzer package in Python (2021), Python-packages at GitHub/antononcube.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for SparseMatrixRecommender-0.1.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1fc3572d99928408143aec104d95958fa8fa91d920251191e501c946f90600a |
|
MD5 | fcdfd9b2e2e4259758df1c34368080c0 |
|
BLAKE2b-256 | 27bff5719e66d11fa3721790bb30d5f31fb0150c150b243b2561c9f2df31d814 |
Hashes for SparseMatrixRecommender-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c109b094b7c2d36f2925dab2fb4933af179de14f6d2217e9b7ca73566aa7d8f5 |
|
MD5 | fdf28968fd2c8e76be122044688d018c |
|
BLAKE2b-256 | c4742e05b090be485179ee9b454dffef960ad2f0a6c88fdbac1a23754e5ec3f6 |