pythondjango项目集成,如何将推荐系统(python文件)集成到django项目中。

This is the python script made by my friend .How to integrate this file in my django project which contains all list of movies taken from the movierulz data set.Where should I integrate this code.

import numpy as np

import pandas as pd

# set some print options

np.set_printoptions(precision=4)

np.set_printoptions(threshold=5)

np.set_printoptions(suppress=True)

pd.set_option('precision', 3, 'notebook_repr_html', True, )

# init random gen

np.random.seed(2)

#users_file = "/media/sourabhkondapaka/Sourabh's/main_project/sandbox/ml-latest-small/ratings.csv"

#movies_file = "/media/sourabhkondapaka/Sourabh's/main_project/sandbox/ml-latest-small/movies.csv"

#users = pd.read_table(users_file,sep=',', header=None,names = ['user_id','movie_id','rating','timestamp'])

#movies = pd.read_table(movies_file, sep=',')

class popularity_based():

def __init__(self,users,movies):

self.users = users

self.movies = movies

self.user_id = None

self.mean_ratings = None

self.movielens= None

self.c = 0

def create(self):

self.movielens = pd.merge(users,movies)

self.movie_ratings = self.movielens.ix[:,1:3]

self.mean_ratings = self.movie_ratings.groupby('movie_id',as_index = True)['rating'].mean().sort_values(ascending = False)

self.mean_ratings = pd.DataFrame(self.mean_ratings).reset_index()

self.mean_ratings['title'] = self.mean_ratings['movie_id'].map(self.movies.set_index('movie_id')['title'])

def recommend(self, user_id,topu): #no arguement required here, just for the sake of uniformness across other recommender implementations

self.user_id = user_id

#From = self.c

#self.c += topu

#To = self.c

print(type(self.mean_ratings.as_matrix(columns=None)))

return self.mean_ratings.ix[:topu,'title'].as_matrix(columns = None)

解决方案

You have to ask yourself, what does this file do? If it functions as a utility that helps you get movie recommendations for a user, then it should be included in your utils.py under the main project. You can then use appropriate relative import and serve the content in the right view.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值