Stream predictor using popularity after 5 days and playlist information

Requirements

Using conda, the requirements are:

  • pandas
  • numpy
  • scikit-learn
  • tpot
  • xgboost
  • ipykernel (to run this jupyter notebook)

There is also a requirements.txt file in the examples directory that has exact package versions that should work with pip.

Documentation

In [1]:
# Note: This is a symbolic link from: datascience/modelling/model_application/
from stream_predictor import streams


import warnings 
warnings.simplefilter("ignore", UserWarning) # Upgraded scikit-learn but using previous version of pickled file
In [2]:
?streams
Signature: streams(pop_5, playlists)
Docstring:
Apply streams model based on popularity after 5 days and playlist that the track exists on, 
including the playlist position. 

NOTE: there is a hardcoded path included here!

Parameters
----------
pop_5: int
    Popularity after 5 days
playlists: dict( playlistId -> position on playlist )
    Playlists and their position

Returns
-------
Predicted total streams after 5 days INCLUDING the first five days
File:      ~/workspace/whitelist/thundr/datascience/examples/stream_predictor/stream_predictor.py
Type:      function

Examples

In [3]:
pop_5 = 45
playlists = {}
streams(pop_5, playlists)
Out[3]:
143129.84320998058
In [4]:
pop_5 = 45
playlists = {'37i9dQZEVXbLRQDuF5jeBp' : 8 }
streams(pop_5, playlists)
Out[4]:
164365.71248976173
In [5]:
pop_5 = 45
playlists = {'doesnt_exist' : 1 }
streams(pop_5, playlists)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-e361f53c877b> in <module>()
      1 pop_5 = 45
      2 playlists = {'doesnt_exist' : 1 }
----> 3 streams(pop_5, playlists)

~/workspace/whitelist/thundr/datascience/examples/stream_predictor/stream_predictor.py in streams(pop_5, playlists)
     41 
     42     if(len(unknown_playlists) > 0):
---> 43         raise ValueError(f'There are unknown playlists provided: {unknown_playlists}')
     44 
     45     df = pd.DataFrame(columns=feature_columns)

ValueError: There are unknown playlists provided: ['doesnt_exist']
In [11]:
# This yields a smaller outcome than the previous with only the first playlist
pop_5 = 45
playlists = {'37i9dQZEVXbLRQDuF5jeBp' : 1, '0JyJ4Nt68jBV0sJUErDlmx':1}
streams(pop_5, playlists)
Out[11]:
164146.11022053924