Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Machine Learning for the Web

You're reading from   Machine Learning for the Web Gaining insight and intelligence from the internet with Python

Arrow left icon
Product type Paperback
Published in Jul 2016
Publisher Packt
ISBN-13 9781785886607
Length 298 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Andrea Isoni Andrea Isoni
Author Profile Icon Andrea Isoni
Andrea Isoni
Steve Essinger Steve Essinger
Author Profile Icon Steve Essinger
Steve Essinger
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Introduction to Practical Machine Learning Using Python FREE CHAPTER 2. Unsupervised Machine Learning 3. Supervised Machine Learning 4. Web Mining Techniques 5. Recommendation Systems 6. Getting Started with Django 7. Movie Recommendation System Web Application 8. Sentiment Analyser Application for Movie Reviews Index

PageRank: Django view and the algorithm code


To rank the importance of the online reviews, we have implemented the PageRank algorithm (see Chapter 4, Web Mining Techniques, in the Ranking: PageRank algorithm section) into the application. The pgrank.py file in the pgrank folder within the webmining_server folder implements the algorithm that follows:

from pages.models import Page,SearchTerm

num_iterations = 100000
eps=0.0001
D = 0.85

def pgrank(searchid):
    s = SearchTerm.objects.get(id=int(searchid))
    links = s.links.all()
    from_idxs = [i.from_id for i in links ]
    # Find the idxs that receive page rank 
    links_received = []
    to_idxs = []
    for l in links:
        from_id = l.from_id
        to_id = l.to_id
        if from_id not in from_idxs: continue
        if to_id  not in from_idxs: continue
        links_received.append([from_id,to_id])
        if to_id  not in to_idxs: to_idxs.append(to_id)
        
    pages = s.pages.all()
    prev_ranks = dict()
    for node...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image