如何构建奇异值分解(SVD)建议模型(pkl) [英] How to build model for Singular Value Decomposition (SVD) Recommendation (pkl)

查看:105
本文介绍了如何构建奇异值分解(SVD)建议模型(pkl)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好


为了注册Azure ML服务的模型,需要为SVD建议创建模型


我们有只是预测的评级而不是Sklearn中定义的Model对象。这是

完整参考
 示例


来自scipy.sparse.linalg import svds


all_user_predicted_ratings = np.dot( np.dot(U,sigma),Vt)+ user_ratings_mean.reshape(-1,1)

preds_df = pd.DataFrame(all_user_predicted_ratings,columns = df_clean_matrix.columns)

preds_df ['reviewerID'] = users_df

preds_df.set_index('reviewerID',inplace = True)

preds_df  (---> 如果必须将其作为pickle文件转储?并注册为模型?)


最后我们需要调用此函数


sorted_user_predictions,recommendations = recommended_method(preds_df,'AZYZQ7I9L7G3G',df2,10)( - >如果必须在部署时调用,如下所示?)


    

def init():

   全球模特



    model_path = Model.get_model_path('recommendation.pkl')

    #将模型文件反序列化为sklearn模型

    model = joblib.load(model_path)


#note你可以传入多行进行评分

def run(raw_data):

   尝试:

        data = json.loads(raw_data)['data']

        data = numpy.array(数据)

        result = model.predict_proba(data)[:,1]


          sorted_user_predictions,recommendations = recommended_method(preds_df,'AZYZQ7I9L7G3G',df2,10)


         #只要JSON可序列化,您就可以返回任何数据类型

        return result.tolist()

   除了e例外:

       错误= str(e)

       返回错误



但我们如何确切地检索建议 如上所述使用SVD?




解决方案

您好,


您所指的代码示例似乎不是Microsoft文档,因此我很难解释此示例。希望有其他工程师对样本有洞察力。


对于奇异值分解,我发现一个我认为可以帮助你的博客,请参考它。  http://nicolas-hug.com/blog/matrix_facto_3


问候,


宇通


Hi

In order to register the model for Azure ML service, need to create the model for SVD recommendation

we have just predicted ratings instead of the Model object defined in Sklearn .. This is the full reference example

from scipy.sparse.linalg import svds

all_user_predicted_ratings = np.dot(np.dot(U, sigma), Vt) + user_ratings_mean.reshape(-1, 1)
preds_df = pd.DataFrame(all_user_predicted_ratings, columns = df_clean_matrix.columns)
preds_df['reviewerID'] = users_df
preds_df.set_index('reviewerID', inplace=True)
preds_df  ( ---> if this has to be dumped as the pickle file ? and register as the model ?)

And finally we need to call this function

sorted_user_predictions,recommendations = recommend_method(preds_df,'AZYZQ7I9L7G3G',df2,10)( --> If this has to be  be called while  deploying as below?)

    

def init():
    global model

    model_path = Model.get_model_path('recommendation.pkl')
    # deserialize the model file back into a sklearn model
    model = joblib.load(model_path)

# note you can pass in multiple rows for scoring
def run(raw_data):
    try:
        data = json.loads(raw_data)['data']
        data = numpy.array(data)
        result = model.predict_proba(data)[:,1]

         sorted_user_predictions,recommendations = recommend_method(preds_df,'AZYZQ7I9L7G3G',df2,10)

         # you can return any datatype as long as it is JSON-serializable
        return result.tolist()
    except Exception as e:
        error = str(e)
        return error

But how exactly we can retrieve recommendations  with SVD as described above?


解决方案

Hello,

It seems that the code sample you are referring to is not kind of Microsoft document, so it's hard for me to explain this sample. Hope there are other engineers have insight for the sample.

For Singular Value Decomposition, I found one blog I think may help you, please refer to it. http://nicolas-hug.com/blog/matrix_facto_3

Regards,

Yutong


这篇关于如何构建奇异值分解(SVD)建议模型(pkl)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆