0

我需要计算给定方程的值。但变量有不同的形状。

from scipy.sparse import csr_matrix
import pandas as pd
import numpy as np

数据集:

    sample_data_dict = {
     'item_id': {0: 1, 1: 2, 2: 3, 3: 4},
     'rating': {0: 3, 1: 5, 2: 4, 3: 4,},
     'user_id': {0: 4, 1: 4, 2: 5, 3: 6}}
    
    sub_data = pd.DataFrame.from_dict(sample_data_dict)

#computing adjacency matrix
a = csr_matrix((sub_data['rating], (sub_data['user_id], sub_data['item_id]))).toarray()  

#computing mean
mu = sub_data['rating].mean()

#svd decomposition
U, Sigma, V = randomized_svd(a, n_components=5,n_iter=5, random_state=None)

#computing bias terms
b_i = np.zeros(U.shape)
c_j = np.zeros(VT.shape)

alpha = 0.01

Equation to solve:
2*((alpha * b_i) - rating + mu + b_i + c_j + np.dot(U.T*V))

有人可以通过知道如何计算来帮助我,因为所有参数都具有不同的形状

4

0 回答 0