Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
positives_lookup,
interactions.row,
shuffle_indices,
lightfm_data,
self.learning_rate,
self.item_alpha,
self.user_alpha,
self.k,
self.n,
num_threads,
self.random_state,
)
else:
fit_logistic(
CSRMatrix(item_features),
CSRMatrix(user_features),
interactions.row,
interactions.col,
interactions.data,
sample_weight,
shuffle_indices,
lightfm_data,
self.learning_rate,
self.item_alpha,
self.user_alpha,
num_threads,
)
interactions.row,
interactions.col,
interactions.data,
sample_weight,
shuffle_indices,
lightfm_data,
self.learning_rate,
self.item_alpha,
self.user_alpha,
num_threads,
self.random_state,
)
elif loss == "warp-kos":
fit_warp_kos(
CSRMatrix(item_features),
CSRMatrix(user_features),
positives_lookup,
interactions.row,
shuffle_indices,
lightfm_data,
self.learning_rate,
self.item_alpha,
self.user_alpha,
self.k,
self.n,
num_threads,
self.random_state,
)
else:
fit_logistic(
CSRMatrix(item_features),
CSRMatrix(user_features),
)
n_users = user_ids.max() + 1
n_items = item_ids.max() + 1
(user_features, item_features) = self._construct_feature_matrices(
n_users, n_items, user_features, item_features
)
lightfm_data = self._get_lightfm_data()
predictions = np.empty(len(user_ids), dtype=np.float64)
predict_lightfm(
CSRMatrix(item_features),
CSRMatrix(user_features),
user_ids,
item_ids,
predictions,
lightfm_data,
num_threads,
)
return predictions
CSRMatrix(user_features),
positives_lookup,
interactions.row,
shuffle_indices,
lightfm_data,
self.learning_rate,
self.item_alpha,
self.user_alpha,
self.k,
self.n,
num_threads,
self.random_state,
)
else:
fit_logistic(
CSRMatrix(item_features),
CSRMatrix(user_features),
interactions.row,
interactions.col,
interactions.data,
sample_weight,
shuffle_indices,
lightfm_data,
self.learning_rate,
self.item_alpha,
self.user_alpha,
num_threads,
)
interactions.row,
interactions.col,
interactions.data,
sample_weight,
shuffle_indices,
lightfm_data,
self.learning_rate,
self.item_alpha,
self.user_alpha,
num_threads,
self.random_state,
)
elif loss == "bpr":
fit_bpr(
CSRMatrix(item_features),
CSRMatrix(user_features),
positives_lookup,
interactions.row,
interactions.col,
interactions.data,
sample_weight,
shuffle_indices,
lightfm_data,
self.learning_rate,
self.item_alpha,
self.user_alpha,
num_threads,
self.random_state,
)
elif loss == "warp-kos":
fit_warp_kos(
CSRMatrix(item_features),
positives_lookup,
interactions.row,
interactions.col,
interactions.data,
sample_weight,
shuffle_indices,
lightfm_data,
self.learning_rate,
self.item_alpha,
self.user_alpha,
num_threads,
self.random_state,
)
elif loss == "warp-kos":
fit_warp_kos(
CSRMatrix(item_features),
CSRMatrix(user_features),
positives_lookup,
interactions.row,
shuffle_indices,
lightfm_data,
self.learning_rate,
self.item_alpha,
self.user_alpha,
self.k,
self.n,
num_threads,
self.random_state,
)
else:
fit_logistic(
CSRMatrix(item_features),
ranks = sp.csr_matrix(
(
np.zeros_like(test_interactions.data),
test_interactions.indices,
test_interactions.indptr,
),
shape=test_interactions.shape,
)
lightfm_data = self._get_lightfm_data()
predict_ranks(
CSRMatrix(item_features),
CSRMatrix(user_features),
CSRMatrix(test_interactions),
CSRMatrix(train_interactions),
ranks.data,
lightfm_data,
num_threads,
)
return ranks
# The CSR conversion needs to happen before shuffle indices are created.
# Calling .tocsr may result in a change in the data arrays of the COO matrix,
positives_lookup = CSRMatrix(
self._get_positives_lookup_matrix(interactions)
)
# Create shuffle indexes.
shuffle_indices = np.arange(len(interactions.data), dtype=np.int32)
self.random_state.shuffle(shuffle_indices)
lightfm_data = self._get_lightfm_data()
# Call the estimation routines.
if loss == "warp":
fit_warp(
CSRMatrix(item_features),
CSRMatrix(user_features),
positives_lookup,
interactions.row,
interactions.col,
interactions.data,
sample_weight,
shuffle_indices,
lightfm_data,
self.learning_rate,
self.item_alpha,
self.user_alpha,
num_threads,
self.random_state,
)
elif loss == "bpr":
fit_bpr(