original_docstring: Called if script is called from the command line.
docstring: Called if script is called from the command line.
docstring_tokens: Called if script is called from the command line .
code: def main():
      """Called if script is called from the command line."""
  
      # Make sure an IMDB ID and optionally a list of seaons is passed in
      if len(sys.argv) < 2:
          print("USAGE:", sys.argv[0], "imdb_id [seasons]")
          sys.exit(1)
  
      # Get episode ratings for given IMDB ID
      ratings = list(get_series_ratings(sys.argv[1]))
      # Get available season numbers
      seasons = set([int(e[0].split(".")[0]) for e in ratings if "." in e[0]])
      # Lower limit for plot X-axis
      y_lower_lim = 10
  
      # Filter seasons by given string if available
      if len(sys.argv) >= 3:
          filtered_seasons = parse_season_string(sys.argv[2])
          seasons = [season for season in seasons if season in filtered_seasons]
  
      # Get regression model for each season
      for season in seasons:
          # Get model, X and Y data
          X, Y, model = get_model_for_season(ratings, season)
          # Predict regression line using X data
          y_pred = model.predict(X)
  
          # Make sure X values start from 1
          X = [n + 1 for n in X]
  
          # Plot regression line
          lines = plt.plot(X, y_pred)
          # Print scatter plot for ratings using same colour as regression
          plt.scatter(X, Y, color=lines[0]._color)
  
          # Ensure Y axis minimum is lowered if it is lower than `y_lower_lim`
          y_lower_lim = min(flatten(Y) + [y_lower_lim])
  
          # Print average script and R2 score for regression for season
          print(season, "=>", sum(Y) / len(Y), r2_score(Y, y_pred))
  
      # If series contains more than one season, generate regression for entire
      # series
      if len(seasons) > 1:
          # Get model for entire series and predict Y values given X data
          X, Y, model = get_model(ratings)
          y_pred = model.predict(X)
  
          # Plot overall regression as a dashed grey line
          plt.plot(
              [n + 1 for n in X], y_pred,
              color="gray",
              linestyle="dashed",
              linewidth=0.5
          )
  
          # Print R2 score for entire series
          print()
          print("TOTAL:", r2_score(Y, y_pred))
  
      # Set X and Y limits for plit
      plt.xlim(0.5, len(ratings) + 0.5)
      plt.ylim(-0.5, 10.5)
  
      # Add series title as plot title and label axes
      plt.title(ratings[0][1])
      plt.xlabel("Episode")
      plt.ylabel("Rating")
  
      # Show plot
      plt.tight_layout()
      plt.show()
code_tokens: def main ( ) : if len ( sys . argv ) < 2 : print ( "USAGE:" , sys . argv [ 0 ] , "imdb_id [seasons]" ) sys . exit ( 1 ) ratings = list ( get_series_ratings ( sys . argv [ 1 ] ) ) seasons = set ( [ int ( e [ 0 ] . split ( "." ) [ 0 ] ) for e in ratings if "." in e [ 0 ] ] ) y_lower_lim = 10 if len ( sys . argv ) >= 3 : filtered_seasons = parse_season_string ( sys . argv [ 2 ] ) seasons = [ season for season in seasons if season in filtered_seasons ] for season in seasons : X , Y , model = get_model_for_season ( ratings , season ) y_pred = model . predict ( X ) X = [ n + 1 for n in X ] lines = plt . plot ( X , y_pred ) plt . scatter ( X , Y , color = lines [ 0 ] . _color ) y_lower_lim = min ( flatten ( Y ) + [ y_lower_lim ] ) print ( season , "=>" , sum ( Y ) / len ( Y ) , r2_score ( Y , y_pred ) ) if len ( seasons ) > 1 : X , Y , model = get_model ( ratings ) y_pred = model . predict ( X ) plt . plot ( [ n + 1 for n in X ] , y_pred , color = "gray" , linestyle = "dashed" , linewidth = 0.5 ) print ( ) print ( "TOTAL:" , r2_score ( Y , y_pred ) ) plt . xlim ( 0.5 , len ( ratings ) + 0.5 ) plt . ylim ( - 0.5 , 10.5 ) plt . title ( ratings [ 0 ] [ 1 ] ) plt . xlabel ( "Episode" ) plt . ylabel ( "Rating" ) plt . tight_layout ( ) plt . show ( )
short_docstring: Called if script is called from the command line.
short_docstring_tokens: Called if script is called from the command line .
comment: """Called if script is called from the command line."""$SEP$# Make sure an IMDB ID and optionally a list of seaons is passed in$SEP$# Get episode ratings for given IMDB ID$SEP$# Get available season numbers$SEP$# Lower limit for plot X-axis$SEP$# Filter seasons by given string if available$SEP$# Get regression model for each season$SEP$# Get model, X and Y data$SEP$# Predict regression line using X data$SEP$# Make sure X values start from 1$SEP$# Plot regression line$SEP$# Print scatter plot for ratings using same colour as regression$SEP$# Ensure Y axis minimum is lowered if it is lower than `y_lower_lim`$SEP$# Print average script and R2 score for regression for season$SEP$# If series contains more than one season, generate regression for entire$SEP$# series$SEP$# Get model for entire series and predict Y values given X data$SEP$# Plot overall regression as a dashed grey line$SEP$# Print R2 score for entire series$SEP$# Set X and Y limits for plit$SEP$# Add series title as plot title and label axes$SEP$# Show plot