def predict_trend(self): object_type = 'PyTrends.trend_ratio' # Pull and prep data conn = sqlite3.connect("db.sqlite3") df = pd.read_sql_query( "select date as ds, btc_usd, buy_bitcoin, trend_ratio from crypto_track_pytrends;", conn) df['y'] = df['trend_ratio'] df['ds'] = pd.to_datetime(df['ds'], errors='coerce') # Get prior 'y' value to fill in nan df['y-1'] = df.y.shift(1) df['y_nan'] = df.y.isna() df.y.fillna(df['y-1'], inplace=True) df.drop(['y-1'], axis=1, inplace=True) # Instantiate a Prophet object future_trend = Prophet(df, 'Trend Ratio') # Change default attributes as analyzed in Trend Prediction.ipynb notebook. future_trend.weekly_seasonality = True future_trend.training_years = 6 future_trend.changepoint_prior_scale = 0.05 future, train, model = future_trend.predict(self.prediction_days) # Create predictions and load table. return_message = self.dbload_prophet(df=future, object_type=object_type) return return_message