Chapter 7. Movie Recommendation System Web Application

The purpose of this chapter is to explain a real case example of the recommendation system in action, using the Django framework. We are going to implement a movie recommendation system in which each user that subscribes to the service will receive suggested movies based on his preferences as we have discussed in Chapter 5, Recommendation systems, also we are going to use the same data which consists of 603 movies rated more than 50 times by 942 users. In order to receive recommendations, each user has to rate a certain number of movies, so an information retrieval system (Chapter 4, Web-mining techniques) to search the movies to rate is implemented. The different parts of the Django application are going to be discussed: settings, models, user login/logout, commands, information retrieval system, recommendation systems, an admin interface and APIs (all the code is available on the GitHub of the author chapter_7 folder at https://github.com/ai2010/machine_learning_for_the_web/tree/master/chapter_7). Since Chapter 6, Basics of Django: a simple web framework just introduced the main features of Django, whenever a new feature is employed a technical explanation is also provided. Now we can start describing the different settings and the initial setup to run the application.

Application setup

We create and start Django as usual:

django-admin startproject server_movierecsys

and from the server_movierecsys folder we start the application:

python manage.py startapp books_recsys_app

Now the settings.py needs to be configured. As we see in Chapter 6, Basics of Django: a simple web framework we set the installed apps, HTML templates, a layout formatting folder, and an SQLite database:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework_swagger',
    'books_recsys_app',
)

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates'),
)
STATIC_URL = '/static/'
STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), )
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

Apart from the standard apps, and the rest framework (swagger), the books_recsys_app has been included in the installed apps list.

In this case, we need to load data persistently in the memory so that the user experience is improved by not calculating or retrieving data at each user request. To save data or the results of expensive calculations in the memory, we set up the cache system of Django in settings.py:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': '/var/tmp/django_cache',
        'TIMEOUT': None,
    }
}

We have chosen the File Based Cache cache type stored in /var/tmp/django_cache and a None timeout which means the data in the cache will never expire.

To use the admin interface, we set up the superuser account through the command:

python manage.py createsuperuser (admin/admin)

The application is live at http://localhost:8000/ by typing:

python manage.py runserver
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.76.164