Skip to content

Commit

Permalink
Added IBPR to the doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Aghiles SALAH committed Oct 14, 2018
1 parent a0c6d7a commit fe7618c
Show file tree
Hide file tree
Showing 13 changed files with 446 additions and 3 deletions.
20 changes: 20 additions & 0 deletions cornac/models/ibpr/recom_ibpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def __init__(self, k=20, max_iter=100, learning_rate = 0.05, lamda = 0.001, batc

# fit the recommender model to the traning data
def fit(self, X):
"""Fit the model to observations.
Parameters
----------
X: scipy sparse matrix, required
the user-item preference matrix (traning data), in a scipy sparse format\
(e.g., csc_matrix).
"""
#change the data to original user Id item Id and rating format
X = X.tocoo() # convert sparse matrix to COOrdiante format
data = np.ndarray(shape=(len(X.data), 3), dtype=float)
Expand All @@ -83,6 +91,18 @@ def fit(self, X):
#predictions are not stored for the same efficiency reasons"""

def predict(self, index_user):
"""Predic the scores (ratings) of a user for all items.
Parameters
----------
index_user: int, required
The index of the user for whom to perform predictions.
Returns
-------
Numpy 1d array
Array containing the predicted values for all items
"""
user_pred = self.U[index_user, :].dot(self.V.T)
# transform user_pred to a flatten array, but keep thinking about another possible format
user_pred = np.array(user_pred, dtype='float64').flatten()
Expand Down
Binary file modified dist/cornac-0.1.0-cp36-cp36m-win_amd64.whl
Binary file not shown.
Binary file modified docs/build/html/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/build/html/.doctrees/models.doctree
Binary file not shown.
325 changes: 325 additions & 0 deletions docs/build/html/_modules/cornac/models/ibpr/recom_ibpr.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/build/html/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ <h1>All modules for which code is available</h1>
<li><a href="cornac/models/cf/recom_pmf.html">cornac.models.cf.recom_pmf</a></li>
<li><a href="cornac/models/context_cf/recom_c2pf.html">cornac.models.context_cf.recom_c2pf</a></li>
<li><a href="cornac/models/hpf/recom_hpf.html">cornac.models.hpf.recom_hpf</a></li>
<li><a href="cornac/models/ibpr/recom_ibpr.html">cornac.models.ibpr.recom_ibpr</a></li>
<li><a href="cornac/models/pcrl/recom_pcrl.html">cornac.models.pcrl.recom_pcrl</a></li>
<li><a href="cornac/models/pmf/recom_pmf.html">cornac.models.pmf.recom_pmf</a></li>
</ul>
Expand Down
5 changes: 5 additions & 0 deletions docs/build/html/_sources/models.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Collaborative Context Poisson Factorization (C2PF)
.. automodule:: cornac.models.c2pf.recom_c2pf
:members:

Indexable Bayesian Personalized Ranking (IBPR)
-----------------------------------------------
.. automodule:: cornac.models.ibpr.recom_ibpr
:members:

Hierarchical Poisson Factorization (HPF)
----------------------------------------
.. automodule:: cornac.models.hpf.recom_hpf
Expand Down
19 changes: 17 additions & 2 deletions docs/build/html/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ <h1 id="index">Index</h1>
| <a href="#E"><strong>E</strong></a>
| <a href="#F"><strong>F</strong></a>
| <a href="#H"><strong>H</strong></a>
| <a href="#I"><strong>I</strong></a>
| <a href="#M"><strong>M</strong></a>
| <a href="#N"><strong>N</strong></a>
| <a href="#P"><strong>P</strong></a>
Expand Down Expand Up @@ -193,15 +194,17 @@ <h2 id="C">C</h2>
</li>
<li><a href="metrics.html#module-cornac.metrics">cornac.metrics (module)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="models.html#module-cornac.models">cornac.models (module)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="models.html#module-cornac.models.bpr.recom_bpr">cornac.models.bpr.recom_bpr (module)</a>
</li>
<li><a href="models.html#module-cornac.models.c2pf.recom_c2pf">cornac.models.c2pf.recom_c2pf (module)</a>
</li>
<li><a href="models.html#module-cornac.models.hpf.recom_hpf">cornac.models.hpf.recom_hpf (module)</a>
</li>
<li><a href="models.html#module-cornac.models.ibpr.recom_ibpr">cornac.models.ibpr.recom_ibpr (module)</a>
</li>
<li><a href="models.html#module-cornac.models.pcrl.recom_pcrl">cornac.models.pcrl.recom_pcrl (module)</a>
</li>
Expand Down Expand Up @@ -229,6 +232,8 @@ <h2 id="F">F</h2>
<li><a href="models.html#cornac.models.c2pf.recom_c2pf.C2pf.fit">(cornac.models.c2pf.recom_c2pf.C2pf method)</a>
</li>
<li><a href="models.html#cornac.models.hpf.recom_hpf.Hpf.fit">(cornac.models.hpf.recom_hpf.Hpf method)</a>
</li>
<li><a href="models.html#cornac.models.ibpr.recom_ibpr.Ibpr.fit">(cornac.models.ibpr.recom_ibpr.Ibpr method)</a>
</li>
<li><a href="models.html#cornac.models.pcrl.recom_pcrl.Pcrl.fit">(cornac.models.pcrl.recom_pcrl.Pcrl method)</a>
</li>
Expand All @@ -250,6 +255,14 @@ <h2 id="H">H</h2>
</ul></td>
</tr></table>

<h2 id="I">I</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="models.html#cornac.models.ibpr.recom_ibpr.Ibpr">Ibpr (class in cornac.models.ibpr.recom_ibpr)</a>
</li>
</ul></td>
</tr></table>

<h2 id="M">M</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
Expand Down Expand Up @@ -289,6 +302,8 @@ <h2 id="P">P</h2>
<li><a href="models.html#cornac.models.c2pf.recom_c2pf.C2pf.predict">(cornac.models.c2pf.recom_c2pf.C2pf method)</a>
</li>
<li><a href="models.html#cornac.models.hpf.recom_hpf.Hpf.predict">(cornac.models.hpf.recom_hpf.Hpf method)</a>
</li>
<li><a href="models.html#cornac.models.ibpr.recom_ibpr.Ibpr.predict">(cornac.models.ibpr.recom_ibpr.Ibpr method)</a>
</li>
<li><a href="models.html#cornac.models.pcrl.recom_pcrl.Pcrl.predict">(cornac.models.pcrl.recom_pcrl.Pcrl method)</a>
</li>
Expand Down
67 changes: 67 additions & 0 deletions docs/build/html/models.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<li class="toctree-l1 current"><a class="current reference internal" href="#">models</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#module-cornac.models.pcrl.recom_pcrl">Probabilistic Collaborative Representation Learning (PCRL)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cornac.models.c2pf.recom_c2pf">Collaborative Context Poisson Factorization (C2PF)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cornac.models.ibpr.recom_ibpr">Indexable Bayesian Personalized Ranking (IBPR)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cornac.models.hpf.recom_hpf">Hierarchical Poisson Factorization (HPF)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cornac.models.bpr.recom_bpr">Bayesian Personalized Ranking (BPR)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-cornac.models.pmf.recom_pmf">Probabilitic Matrix Factorization (PMF)</a></li>
Expand Down Expand Up @@ -299,6 +300,72 @@

</dd></dl>

</div>
<div class="section" id="module-cornac.models.ibpr.recom_ibpr">
<span id="indexable-bayesian-personalized-ranking-ibpr"></span><h2>Indexable Bayesian Personalized Ranking (IBPR)<a class="headerlink" href="#module-cornac.models.ibpr.recom_ibpr" title="Permalink to this headline"></a></h2>
<p>&#64;author: Dung D. Le (Andrew) &lt;<a class="reference external" href="mailto:ddle&#46;2015&#37;&#52;&#48;smu&#46;edu&#46;sg">ddle<span>&#46;</span>2015<span>&#64;</span>smu<span>&#46;</span>edu<span>&#46;</span>sg</a>&gt;</p>
<dl class="class">
<dt id="cornac.models.ibpr.recom_ibpr.Ibpr">
<em class="property">class </em><code class="descclassname">cornac.models.ibpr.recom_ibpr.</code><code class="descname">Ibpr</code><span class="sig-paren">(</span><em>k=20</em>, <em>max_iter=100</em>, <em>learning_rate=0.05</em>, <em>lamda=0.001</em>, <em>batch_size=100</em>, <em>name='ibpr'</em>, <em>trainable=True</em>, <em>init_params=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cornac/models/ibpr/recom_ibpr.html#Ibpr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cornac.models.ibpr.recom_ibpr.Ibpr" title="Permalink to this definition"></a></dt>
<dd><p>Indexable Bayesian Personalized Ranking.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>k</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.7)"><em>int</em></a><em>, </em><em>optional</em><em>, </em><em>default: 20</em>) – The dimension of the latent factors.</li>
<li><strong>max_iter</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.7)"><em>int</em></a><em>, </em><em>optional</em><em>, </em><em>default: 100</em>) – Maximum number of iterations or the number of epochs for SGD.</li>
<li><strong>learning_rate</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.7)"><em>float</em></a><em>, </em><em>optional</em><em>, </em><em>default: 0.05</em>) – The learning rate for SGD.</li>
<li><strong>lamda</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.7)"><em>float</em></a><em>, </em><em>optional</em><em>, </em><em>default: 0.001</em>) – The regularization parameter.</li>
<li><strong>batch_size</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.7)"><em>int</em></a><em>, </em><em>optional</em><em>, </em><em>default: 100</em>) – The batch size for SGD.</li>
<li><strong>name</strong> (<em>string</em><em>, </em><em>optional</em><em>, </em><em>default: 'IBRP'</em>) – The name of the recommender model.</li>
<li><strong>trainable</strong> (<em>boolean</em><em>, </em><em>optional</em><em>, </em><em>default: True</em>) – When False, the model is not trained and Cornac assumes that the model already pre-trained (U and V are not None).</li>
<li><strong>init_params</strong> (<em>dictionary</em><em>, </em><em>optional</em><em>, </em><em>default: None</em>) – List of initial parameters, e.g., init_params = {‘U’:U, ‘V’:V} please see below the definition of U and V.</li>
<li><strong>U</strong> (<em>csc_matrix</em><em>, </em><em>shape</em><em> (</em><em>n_users</em><em>,</em><em>k</em><em>)</em>) – The user latent factors, optional initialization via init_params.</li>
<li><strong>V</strong> (<em>csc_matrix</em><em>, </em><em>shape</em><em> (</em><em>n_items</em><em>,</em><em>k</em><em>)</em>) – The item latent factors, optional initialization via init_params.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">References</p>
<ul class="simple">
<li>Le, D. D., &amp; Lauw, H. W. (2017, November). Indexable Bayesian personalized ranking for efficient top-k recommendation. In Proceedings of the 2017 ACM on Conference on Information and Knowledge Management (pp. 1389-1398). ACM.</li>
</ul>
<dl class="method">
<dt id="cornac.models.ibpr.recom_ibpr.Ibpr.fit">
<code class="descname">fit</code><span class="sig-paren">(</span><em>X</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cornac/models/ibpr/recom_ibpr.html#Ibpr.fit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cornac.models.ibpr.recom_ibpr.Ibpr.fit" title="Permalink to this definition"></a></dt>
<dd><p>Fit the model to observations.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>X</strong> (<em>scipy sparse matrix</em><em>, </em><em>required</em>) – the user-item preference matrix (traning data), in a scipy sparse format (e.g., csc_matrix).</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cornac.models.ibpr.recom_ibpr.Ibpr.predict">
<code class="descname">predict</code><span class="sig-paren">(</span><em>index_user</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cornac/models/ibpr/recom_ibpr.html#Ibpr.predict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cornac.models.ibpr.recom_ibpr.Ibpr.predict" title="Permalink to this definition"></a></dt>
<dd><p>Predic the scores (ratings) of a user for all items.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>index_user</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.7)"><em>int</em></a><em>, </em><em>required</em>) – The index of the user for whom to perform predictions.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Array containing the predicted values for all items</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">Numpy 1d array</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-cornac.models.hpf.recom_hpf">
<span id="hierarchical-poisson-factorization-hpf"></span><h2>Hierarchical Poisson Factorization (HPF)<a class="headerlink" href="#module-cornac.models.hpf.recom_hpf" title="Permalink to this headline"></a></h2>
Expand Down
Binary file modified docs/build/html/objects.inv
Binary file not shown.
5 changes: 5 additions & 0 deletions docs/build/html/py-modindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ <h1>Python Module Index</h1>
<td>&#160;&#160;&#160;
<a href="models.html#module-cornac.models.hpf.recom_hpf"><code class="xref">cornac.models.hpf.recom_hpf</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="models.html#module-cornac.models.ibpr.recom_ibpr"><code class="xref">cornac.models.ibpr.recom_ibpr</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
Expand Down

0 comments on commit fe7618c

Please sign in to comment.