Algorithm module

PodcastRecommendation

__init__(self, uri, auth, x_path=None, y_path=None, verbose=False) special

Creates object. Reads files to train Logistic Regression model.

Parameters:
  • uri (str) – neo4j uri

  • auth (str) – neo4j (user, psw)

  • x_path (str) – path to x_train. Defaults to X_PATH.

  • y_path (str) – path to y_train. Defaults to Y_PATH.

  • verbose (bool) – verbose. Defaults to False.

adamic_adar(self, user_id, podcast_id)

Generates data from Adamic Adar metric

Parameters:
  • user_id (str) – user id

  • podcast_id (str) – podcast id

Returns:
  • list – adamic adar

build_cat(self, row)

Builds relations in categories_sample dataset

Parameters:
  • row (pd.Series) – dataframe row

build_graph(self, cat_path=None, rtg_path=None, delete_all=True, verbose=False)

Builds graph in neo4j

Parameters:
  • cat_path (str) – path to categories_sample. Defaults to CAT_PATH.

  • rtg_path (str) – path to ratings_sample. Defaults to RTG_PATH.

  • delete_all (bool) – if to delete graph before writting. Defaults to True.

  • verbose (bool) – verbose. Defaults to False.

build_rtg(self, row)

Builds relations in ratings_sample dataset

Parameters:
  • row (pd.Series) – dataframe row

close(self)

Closes driver.

create_IsA(self, podcast_id, category)

Creates an IsA relationship

Parameters:
  • podcast_id (str) – podcast id

  • category (str) – category name

create_category(self, category, category_id)

Creates category

Parameters:
  • category (str) – category name

  • category_id (int) – category id

create_podcast(self, podcast_id, title)

Creates a podcast

Parameters:
  • podcast_id (str) – podcast id

  • title (str) – title

create_rtg(self, user_id, podcast_id, rating)

Create rating relationship

Parameters:
  • user_id (str) – user id

  • podcast_id (str) – podcast id

  • rating (int) – rating

create_user(self, user_id)

Creates user

Parameters:
  • user_id (str) – user id

delete_IsA(self, podcast_id, category)

Deletes IsA relationship

Parameters:
  • podcast_id (str) – podcast id

  • category (str) – category name

delete_all(self)

Deletes all elements in the graph

delete_cat(self, category)

Deletes category

Parameters:
  • category (str) – category name

delete_podcast(self, podcast_id)

Deletes podcast

Parameters:
  • podcast_id (str) – podcast id

delete_rtg(self, user_id, podcast_id)

Deletes rating relationship

Parameters:
  • user_id (str) – user id

  • podcast_id (str) – podcast id

delete_user(self, user_id)

Deletes user

Parameters:
  • user_id (str) – user id

gen_data(self, df)

Generates data for podcast recommendation

Parameters:
  • df (pd.DataFrame) – podcasts

Returns:
  • pd.DataFrame – dataframe with attributes

gen_data_row(self, row)

Helper for gen_data

Parameters:
  • row (pd.Series) – row of data

Returns:
  • list – list of attributes

gen_df(self, user_id)

Generates df with podcasts of interest

Parameters:
  • user_id (str) – user id

Returns:
  • pd.DataFrame – dataframe with podcasts

gen_podcasts(self, user_id)

Helper for gen_df. Uses paths (user)-[*3]->(podcast)

Parameters:
  • user_id (str) – user id

Returns:
  • list – list with podcasts

get_cat_based(self, user_id, podcast_id)

Generates data from paths (user)->(podcast)->(category)<-(podcast)

Parameters:
  • user_id (str) – user id

  • podcast_id (str) – podcast id

Returns:
  • list – sum of ratings and count of paths

get_user_based(self, user_id, podcast_id)

Generates data from paths (user)->(podcast)<-(user)->(podcast)

Parameters:
  • user_id (str) – user id

  • podcast_id (str) – podcast id

Returns:
  • list – sum of ratings and count of paths

recommend(self, user_id)

Generates podcast recommendation for user

Parameters:
  • user_id (str) – user id

Returns:
  • pd.DataFrame – podcasts and probabilities

resource_allocation(self, user_id, podcast_id)

Generates data from resource allocation metric

Parameters:
  • user_id (str) – user id

  • podcast_id (str) – podcast id

Returns:
  • list – resource allocation and count of paths