コード例 #1
0
def calc_score(y_true: csr_matrix, y_pred: csr_matrix):
    """Score predictions in csr format"""
    # Hits are when we guessed a track that appeared
    # This is an efficient operation when both entries are csr_matrix instances
    hits = y_true.multiply(y_pred)
    # Sum the hits along the rows; results will be an nx1 array of scores, one for each training point
    scores = np.sum(hits, axis=1)
    # Return the scores as a flattened numpy array
    return scores.A.flatten()
コード例 #2
0
 def transform(self, X: csr_matrix) -> coo_matrix:
     return X.multiply(self.r)