Professional Documents
Culture Documents
import networkx as nx
import pandas as pd
In [3]: G = nx.DiGraph()
G.add_edges_from([('G','A'), ('A','G'),('B','A'),
('C','A'),('A','C'),('A','D'),
('E','A'),('F','A'),('B','D'),
('D','F')])
pos = nx.spiral_layout(G)
print(pr1)
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js
In [5]: pr_09 = nx.pagerank(G, alpha=0.9)
res
A 0.409777 0.389972
B 0.014286 0.028571
C 0.137218 0.132564
D 0.143647 0.143993
E 0.014286 0.028571
F 0.143568 0.143765
G 0.137218 0.132564
print(pr_e)
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js
In [8]: import urllib.request
import shutil
import zipfile
import os
filename='ml-100k'
data_url='https://files.grouplens.org/datasets/movielens/ml-100k.zip'
print('Download completed')
zip_ref.extractall('./sample_data/')
dirs = [x[0] for x in os.walk("./sample_data")]
dt_dir_name= list(ml)[0]
item_data.columns = ['movieId','movieTitle']
item_data = item_data.set_index('movieId')
rdata.head()
Download completed
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js
Out[8]: userId movieId rating timestamp
rdata.head()
3 u244 i51 2 880606923 Legends of the Fall (1994) Legends of the Fall (1994)
G = nx.Graph()
#Add nodes
G.add_nodes_from(rdata.userId, bipartite=0)
G.add_nodes_from(rdata.movieId, bipartite=1)
print(nx.info(G))
print(nx.is_bipartite(G))
True
C:\Users\Vainavi\AppData\Local\Temp\ipykernel_2460\255363031.py:9: DeprecationWarning: i
nfo is deprecated and will be removed in version 3.0.
print(nx.info(G))
top_10_movies = []
if 'i' in key:
top_10_movies.append(key)
if len(top_10_movies) == 10:
break
return item_data.loc[top_10_movies]
In [14]: return_top_movies(movie_rank)
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js
Out[14]: movieTitle
movieId
return_top_movies(recommendation)
Out[15]: movieTitle
movieId
i8 Babe (1995)
In [ ]:
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js