def build_interactions(self, data):
interactions = _IncrementalCOOMatrix(self.interactions_shape(), np.int32)<EOL>weights = _IncrementalCOOMatrix(self.interactions_shape(), np.float32)<EOL>for datum in data:<EOL><INDENT>user_idx, item_idx, weight = self._unpack_datum(datum)<EOL>interactions.append(user_idx, item_idx, <NUM_LIT:1>)<EOL>weights.append(user_idx, item_idx, weight)<EOL><DEDENT>return (interactions.tocoo(), weights.tocoo())<EOL>
Build an interaction matrix.

Two matrices will be returned: a (num_users, num_items)
COO matrix with interactions, and a (num_users, num_items)
matrix with the corresponding interaction weights.

Parameters
----------

data: iterable of (user_id, item_id) or (user_id, item_id, weight)
    An iterable of interactions. The user and item ids will be
    translated to internal model indices using the mappings
    constructed during the fit call. If weights are not provided
    they will be assumed to be 1.0.

Returns
-------

(interactions, weights): COO matrix, COO matrix
    Two COO matrices: the interactions matrix
    and the corresponding weights matrix.