% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/CF.R
\name{CF}
\alias{CF}
\title{Recommendation by Collaborative Filtering}
\description{
CF is a class of objects that stores
information about a recommendation system. This information includes the
consumption or rating of each (user, item) pair in the utility matrix MU, the
similarities between each pair of users in the similarity matrix SU, the
similarities between each pair of items in the similarity matrix SI, the
number of items consumed and/or rated by each user in the vector n_aval_u,
the number of users who consumed and/or rated each item in the vector
n_aval_i, the average rating value of each user in the vector averages_u, the
average rating value received by each item in the vector averages_i, the
number of items consumed in common by each pair of users in the matrix Int_U,
and the number of users in common for each pair of items in the matrix Int_I.
The class contains methods such as addNewUser, addNewEmptyUser, deleteUser,
addNewItem, addNewEmptyItem, deleteItem, newRating and deleteRating, which
modify the object's structure by altering users, items, or consumption data.
The class also includes functions such as kClosestItems, topKUsers, and
topKItems, which return items to recommend to a user or users to whom an item
should be recommended. An object of the CF class is created using the
CFBuilder function.
}
\details{
This class implements a collaborative filtering system supporting both
explicit (ratings) and implicit (consumption) feedback. The internal state
is updated incrementally after each operation.
}
\examples{
data(movies, package = "CFilt")
# --- Rating data ---
objectCF_r <- CFbuilder(Data = movies[1:500,],Datatype = "rating",
similarity = "pearson")
dim(objectCF_r$MU)
colnames(objectCF_r$MU) #movies Id
rownames(objectCF_r$MU) #users Id
dim(objectCF_r$SU)
dim(objectCF_r$SI)
objectCF_r$averages_u
objectCF_r$averages_i
objectCF_r$n_aval_u
objectCF_r$n_aval_i
objectCF_r$addnewemptyuser(Id_u = "newuser1")
objectCF_r$newrating(Id_u = "newuser1",Id_i = "Frozen",r = 5)
objectCF_r$MU["newuser1","Frozen"]
objectCF_r$newrating(Id_u = list("newuser1","newuser1","newuser1"),
Id_i = list("Thor: The Dark World","The Lego Movie","Despicable Me 2"),
r = list(2,3,4))
objectCF_r$n_aval_u["newuser1"]
objectCF_r$averages_u["newuser1"]
objectCF_r$addnewemptyuser(Id_u = "newuser2")
objectCF_r$newrating(Id_u = list("newuser2","newuser1"),
Id_i = list("Frozen","Her"),r = c(2,1))
objectCF_r$addnewemptyuser(Id_u = list("newuser3","newuser4"))
objectCF_r$newrating(Id_u = list("newuser3","newuser3","newuser4","newuser4"),
Id_i = list("The Lego Movie","Wreck-It Ralph","Fast & Furious 6",
"12 Years a Slave"),r = list(4,5,4,2))
objectCF_r$addnewemptyitem(Id_i = list("movie1","movie2","movie3"))
objectCF_r$newrating(
Id_u = list("newuser1","newuser1","newuser1",
           "newuser2","newuser2","newuser2",
           "newuser3","newuser3","newuser3",
           "newuser4","newuser4","newuser4"),
Id_i = list("movie1","movie2","movie3",
           "movie1","movie2","movie3",
           "movie1","movie2","movie3",
           "movie1","movie2","movie3"),
r = list(4,5,4,2,
        1,2,1,1,
        4,3,1,2))
objectCF_r$MU[,"movie1"]
objectCF_r$SI["movie1","movie2"]
objectCF_r$SU["newuser2","newuser4"]
# --- Consumption data ---
objectCF_c <- CFbuilder(Data = movies[1:300,-3],Datatype = "consumption",
similarity = "jaccard")
objectCF_c$addnewemptyuser(Id_u = list("newuser1","newuser2","newuser3"))
objectCF_c$newrating(Id_u = list("newuser1","newuser2","newuser3"),
Id_i = list("Frozen","Frozen","Frozen"))
objectCF_c$newrating(Id_u = list("newuser1","newuser1","newuser1"),
Id_i = list("Gravity","The Wolverine","Iron Man 3"))
objectCF_c$addnewemptyitem(Id_i = list("movie1","movie2","movie3"))
objectCF_c$newrating(Id_u = list("newuser1","newuser1","newuser2","newuser2",
"newuser3"),Id_i = list("movie1","movie2","movie1","movie3","movie3"))
objectCF_c$MU[,"movie1"]
objectCF_c$SI["movie1","movie2"]
objectCF_c$SI["movie1","movie3"]
objectCF_c$SI["movie2","movie3"]
objectCF_c$SU["newuser1","newuser2"]
objectCF_c$SU["newuser2","newuser3"]
}
\references{
\itemize{
\item LINDEN, G.; SMITH, B.; YORK, J. Amazon. com recommendations:
Item-to-item collaborative filtering. Internet Computing, IEEE, v. 7, n. 1,
p. 76-80,2003
\item Aggarwal, C. C. (2016). Recommender systems (Vol. 1). Cham: Springer
International Publishing.
\item Leskovec, J., Rajaraman, A., & Ullman, J. D. (2020). Mining of massive
data sets. Cambridge university press.
}
}
\seealso{
\code{\link[CFilt]{CFbuilder}}
}
\author{
Jessica Kubrusly
}
\section{Public fields}{
\if{html}{\out{<div class="r6-fields">}}
\describe{
\item{\code{MU}}{The Utility Matrix, a matrix that contains all the users' ratings.
The rows comprise users and the columns, items.}

\item{\code{SU}}{The user similarity matrix.}

\item{\code{SI}}{The item similarity matrix}

\item{\code{IntU}}{A symmetric matrix that records the number of items in common
between pairs of users.}

\item{\code{IntI}}{A symmetric matrix that records the number of users in common
between pairs of items.umber of items in common that}

\item{\code{averages_u}}{A vector that contains the averages of users' ratings.}

\item{\code{averages_i}}{A vector that contains the averages of items' ratings.}

\item{\code{n_aval_u}}{A vector that stores the number of items rated by each user.}

\item{\code{n_aval_i}}{A vector that stores the number of users who consumed each
item.}

\item{\code{datatype}}{A character that indicates the type of data, which can be
either "consumption" or "rating".}

\item{\code{similarity}}{A character string indicating the similarity measure used.
It can be "pearson" or "cosine" for rating data, and "jaccard" for consumption data.}

\item{\code{data_0}}{A data.frame containing the original dataset used to build the object.
This corresponds to the input data provided to CFbuilder and is stored for reference.}
}
\if{html}{\out{</div>}}
}
\section{Methods}{
\subsection{Public methods}{
\itemize{
\item \href{#method-CF-addnewemptyuser}{\code{CF$addnewemptyuser()}}
\item \href{#method-CF-addnewemptyitem}{\code{CF$addnewemptyitem()}}
\item \href{#method-CF-newrating}{\code{CF$newrating()}}
\item \href{#method-CF-deleteuser}{\code{CF$deleteuser()}}
\item \href{#method-CF-deleteitem}{\code{CF$deleteitem()}}
\item \href{#method-CF-deleterating}{\code{CF$deleterating()}}
\item \href{#method-CF-clone}{\code{CF$clone()}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-CF-addnewemptyuser"></a>}}
\if{latex}{\out{\hypertarget{method-CF-addnewemptyuser}{}}}
\subsection{Method \code{addnewemptyuser()}}{
Add a new empty user to the system.
This method creates a new user with no interactions.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{CF$addnewemptyuser(Id_u)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{Id_u}}{A character string (or a list of strings) representing user ID(s).}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
Invisibly returns the updated object.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-CF-addnewemptyitem"></a>}}
\if{latex}{\out{\hypertarget{method-CF-addnewemptyitem}{}}}
\subsection{Method \code{addnewemptyitem()}}{
Add a new empty item to the system.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{CF$addnewemptyitem(Id_i)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{Id_i}}{A character string (or list of strings) representing item ID(s).}
}
\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-CF-newrating"></a>}}
\if{latex}{\out{\hypertarget{method-CF-newrating}{}}}
\subsection{Method \code{newrating()}}{
Add a new rating or consumption.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{CF$newrating(Id_u, Id_i, r = NULL)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{Id_u}}{A character string (or a list of strings) representing user ID(s).}

\item{\code{Id_i}}{A character string (or a list of strings) representing item ID(s).}

\item{\code{r}}{A numeric (or a list of numeric) for rating value(s) (only for rating data)}
}
\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-CF-deleteuser"></a>}}
\if{latex}{\out{\hypertarget{method-CF-deleteuser}{}}}
\subsection{Method \code{deleteuser()}}{
Delete a user from the system.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{CF$deleteuser(Id_u)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{Id_u}}{A character string (or a list of strings) representing user ID(s).}
}
\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-CF-deleteitem"></a>}}
\if{latex}{\out{\hypertarget{method-CF-deleteitem}{}}}
\subsection{Method \code{deleteitem()}}{
Delete an item from the system.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{CF$deleteitem(Id_i)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{Id_i}}{A character string (or a list of strings) representing item ID(s).}
}
\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-CF-deleterating"></a>}}
\if{latex}{\out{\hypertarget{method-CF-deleterating}{}}}
\subsection{Method \code{deleterating()}}{
Delete a rating or consumption.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{CF$deleterating(Id_u, Id_i)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{Id_u}}{A character string (or a list of strings) representing user ID(s).}

\item{\code{Id_i}}{A character string (or a list of strings) representing item ID(s).}
}
\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-CF-clone"></a>}}
\if{latex}{\out{\hypertarget{method-CF-clone}{}}}
\subsection{Method \code{clone()}}{
The objects of this class are cloneable with this method.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{CF$clone(deep = FALSE)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{deep}}{Whether to make a deep clone.}
}
\if{html}{\out{</div>}}
}
}
}
