Ejemplo n.º 1
0
def learning(method, train_matrix, train_index, data, user_list, item_list):
    if method == "SVD":
        u, s, vt = svds(train_matrix, k=attribute)
        s_diag_matrix = np.diag(s)
        return np.dot(np.dot(u, s_diag_matrix), vt)
    elif method == "ML3_liner":
        u, v = pv.rmrate(train_index, data, user_list, item_list, attribute)
        R = ml.pv_ml3(train_matrix, eta0, u, v, attribute)
        return np.dot(np.dot(u, R), v.T)
Ejemplo n.º 2
0
def learning(method, train_matrix, train_index, data, user_list, item_list):
    if method == "SVD":
        u, s, vt = svds(train_matrix, k=attribute)
        np.savetxt("u.csv", u, delimiter=",")
        np.savetxt("s.csv", s, delimiter=",")
        np.savetxt("vt.csv", vt, delimiter=",")
        s_diag_matrix = np.diag(s)
        return u
    elif method == "ML3_liner":
        u, v = pv.rmrate(train_index, data, user_list, item_list, attribute)
        R = ml.pv_ml3(train_matrix, eta0, u, v, attribute)
        return u
Ejemplo n.º 3
0
def learning(method, train_matrix, train_index, data, user_list, item_list):
  if method == "SVD":
    u, s, vt = svds(train_matrix, k=attribute)
    np.savetxt("u.csv", u, delimiter=",")
    np.savetxt("s.csv", s, delimiter=",")
    np.savetxt("vt.csv", vt, delimiter=",")
    s_diag_matrix = np.diag(s)
    return u
  elif method == "PMF":
    pmf = nimfa.Pmf(train_matrix.toarray(), seed="random_vcol", rank=attribute, max_iter=50, rel_error=1e-5)
    pmf_fit = pmf()
    return np.array(pmf_fit.fitted())
  elif method == "NMF":
    nmf = nimfa.Nmf(train_matrix, seed="random_vcol", rank=attribute, max_iter=100, rel_error=1e-5, update='euclidean')
    nmf_fit = nmf()
    return nmf_fit.fitted().toarray()
  elif method == "RMrate_liner":
    u, v = pv.rmrate_standard(train_index, data, user_list, item_list, attribute)
    return u
  elif method == "D1_liner":
    u, v = pv.rmrate(train_index, data, user_list, item_list, attribute)
    R = np.c_[np.identity(attribute), -np.identity(attribute)]
    return u
  elif method == "D2_liner":
    u, v = pv.rmrate(train_index, data, user_list, item_list, attribute)
    R = np.c_[2 * np.identity(attribute), -np.identity(attribute)]
    return u
  elif method == "D3_liner":
    u, v = pv.rmrate(train_index, data, user_list, item_list, attribute)
    R = np.c_[np.identity(attribute), -2 * np.identity(attribute)]
    return u
  elif method == "D4_liner":
    u, v = pv.rmrate(train_index, data, user_list, item_list, attribute)
    R = np.c_[np.identity(attribute), np.zeros((attribute, attribute))]
    return u
  elif method == "D5_liner":
    u, v = pv.rmrate(train_index, data, user_list, item_list, attribute)
    R = np.c_[np.zeros((attribute, attribute)), -np.identity(attribute)]
    return u
  elif method == "ML1_liner":
    u, v = pv.rmrate(train_index, data, user_list, item_list, attribute)
    R = ml.pv_ml1(train_matrix, eta0, u, v, attribute)
    return u
  elif method == "ML2_liner":
    u, v = pv.rmrate(train_index, data, user_list, item_list, attribute)
    R = ml.pv_ml2(train_matrix, eta0, u, v, attribute)
    return u
  elif method == "ML3_liner":
    u, v = pv.rmrate(train_index, data, user_list, item_list, attribute)
    R = ml.pv_ml3(train_matrix, eta0, u, v, attribute)
    return u
  elif method == "R2_RMrate":
    u, v = pv.rmrate_square_standard(train_index, data, user_list, item_list, attribute)
    return u
  elif method == "D1_sqaure":
    u, v = pv.rmrate_square(train_index, data, user_list, item_list, attribute)
    R = np.c_[np.identity(attribute), -np.identity(attribute)]
    return u
  elif method == "D2_square":
    u, v = pv.rmrate_square(train_index, data, user_list, item_list, attribute)
    R = np.c_[2 * np.identity(attribute), -np.identity(attribute)]
    return u
  elif method == "D3_square":
    u, v = pv.rmrate_square(train_index, data, user_list, item_list, attribute)
    R = np.c_[np.identity(attribute), -2 * np.identity(attribute)]
    return u
  elif method == "D4_square":
    u, v = pv.rmrate_square(train_index, data, user_list, item_list, attribute)
    R = np.c_[np.identity(attribute), np.zeros((attribute, attribute))]
    return u
  elif method == "D5_square":
    u, v = pv.rmrate_square(train_index, data, user_list, item_list, attribute)
    R = np.c_[np.zeros((attribute, attribute)), -np.identity(attribute)]
    return u
  elif method == "ML1_square":
    u, v = pv.rmrate_square(train_index, data, user_list, item_list, attribute)
    R = ml.pv_ml1(train_matrix, eta0, u, v, attribute)
    return u
  elif method == "ML2_square":
    u, v = pv.rmrate_square(train_index, data, user_list, item_list, attribute)
    R = ml.pv_ml2(train_matrix, eta0, u, v, attribute)
    return u
  elif method == "ML3_square":
    u, v = pv.rmrate_square(train_index, data, user_list, item_list, attribute)
    R = ml.pv_ml3(train_matrix, eta0, u, v, attribute)
    return u