0% found this document useful (0 votes)
19 views5 pages

Data Mining Lab: Assessment

This document contains code to implement the HITS algorithm for ranking web pages based on their hub and authority scores. The code defines an adjacency matrix representing the link structure between 9 web pages. It initializes the hub and authority scores of each page to 1. It then iteratively calculates the authority scores as the adjacency matrix multiplied by the hub scores, and calculates the hub scores as the adjacency matrix transposed multiplied by the authority scores. Finally it prints out the final hub and authority scores for each page.

Uploaded by

Jenil Mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

Data Mining Lab: Assessment

This document contains code to implement the HITS algorithm for ranking web pages based on their hub and authority scores. The code defines an adjacency matrix representing the link structure between 9 web pages. It initializes the hub and authority scores of each page to 1. It then iteratively calculates the authority scores as the adjacency matrix multiplied by the hub scores, and calculates the hub scores as the adjacency matrix transposed multiplied by the authority scores. Finally it prints out the final hub and authority scores for each page.

Uploaded by

Jenil Mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CSE3019

DATA MINING LAB


ASSESSMENT 4

JENIL MEHTA
17BCE0579
FACULTY: LOKESHKUMAR R
CODE:

import numpy as np
print("Enter number of nodes")
num_nodes = int(input())
print("Enter damping factor")
d=float(input())

print("Enter number of iterations")


n=int(input())
matrix=[]
print("Enter the probability matrix")
for i in range(num_nodes):

r=list(map(float,input().split(',')))
matrix.append(r)
a=np.array(matrix)
d_matrix = np.array([[d]]*a.shape[1])
a_trans=a.T
for i in range(n):
a1 = np.matmul(a_trans, d_matrix)
d_matrix = a1

print('Page Ranks for matrix of size ' + str(a.shape[0]))


l={}
for i in range(num_nodes):
l[str(i)]=d_matrix[i][0]
sorted_by_value = sorted(l.items(), key=lambda x: x[1])

print(sorted_by_value)

OUTPUT:
CODE:
import numpy as np
adjacency_mtx = np.matrix([
[0,1,1,0,0,0,0,0,0],
[0,0,0,1,0,0,0,0,0],

[0,0,0,0,0,0,0,0,1],
[0,0,0,0,1,0,1,0,0],
[0,0,1,0,0,0,1,0,0],
[0,1,0,0,0,0,1,0,0],
[0,0,0,0,0,0,0,1,1],

[0,0,0,0,0,1,0,0,1],
[0,0,0,0,0,0,0,0,0]
])
hub_score = np.matrix([ #initial guess
[1],

[1],
[1],
[1],
[1],
[1],
[1],

[1],
[1]
])
authority_score = np.matrix.transpose(adjacency_mtx)*hub_score
hub_score = adjacency_mtx*authority_score

auth={}
hub={}
for i in range(9):
auth[i+1]=int(authority_score[i][0])
hub[i+1]=int(hub_score[i][0])

print("Authority Score -> \n",auth)


print("Hub Score -> \n",hub)
OUTPUT:

You might also like