title: (Featuretools) How are aggregate feature primitives calculated?
body: <p>I have no idea how are aggregated feature primitive calculated even if I tested with very simple data. I looked out the featuretools code as well but couldn't find out where the aggregation operation happened.</p>
  
  <p>Here are sample codes:</p>
  
  <pre><code>from sklearn.utils import shuffle
  
  periods = 5
  end_date = "2012-04-13"
  train_df = pd.DataFrame(
      {
          "store_id": [0]*periods + [1]*periods + [2]*periods + [3]*periods,
          "region": ["A"]*periods+["B"]*periods*3,
          "amount": shuffle(range(periods*4)),
          "transacted_date": [
              "2012-02-05", "2012-02-10", "2012-03-01", "2012-03-18", "2012-04-23",
          ]*4
      }
  )
  train_df["transacted_date"] = pd.to_datetime(train_df["transacted_date"])
  train_df.sort_values(["store_id", "transacted_date"], inplace=True)
  
  
  def make_retail_cutoffs_amounts(data_df, amount_start_date, amount_end_date):
      store_pool = data_df[data_df['transacted_date'] &lt; amount_start_date]['store_id'].unique()
      tmp = pd.DataFrame({'store_id': store_pool})
  
      amounts = data_df[
          (data_df['store_id'].isin(store_pool)) &amp;
          (amount_start_date &lt;= data_df['transacted_date']) &amp;
          (data_df['transacted_date'] &lt; amount_end_date)
      ].groupby('store_id')['amount'].sum().reset_index()
  
      amounts = amounts.merge(tmp, on = 'store_id', how = 'right')
      amounts['amount'] = amounts['amount'].fillna(0)  # 0으로 채워지는 애는 3개월 다 수익이 없는 녀석!
  
      amounts['cutoff_time'] = pd.to_datetime(amount_start_date)
  
      amounts = amounts[['store_id', 'cutoff_time', 'amount']]
      amounts = amounts.rename(columns={"amount":"1month_amount_from_cutoff_time"})
      return amounts
  
  
  amount_start_date = "2012-02-01"
  amount_end_date = end_date
  agg_month = 1
  
  data_df_list = []
  date_list = pd.date_range(amount_start_date, datetime.strptime(end_date, "%Y-%m-%d") + pd.DateOffset(months=1), freq="MS")
  
  for amount_start_date, amount_end_date in zip(date_list[:-agg_month], date_list[agg_month:]):
      data_df_list.append(
          make_retail_cutoffs_amounts(
              train_df, amount_start_date, amount_end_date
          )
      )
  data_df = pd.concat(data_df_list)
  data_df.sort_values(["store_id", "cutoff_time", ], inplace=True)
  
  import featuretools as ft
  
  es = ft.EntitySet(id="sale_set")
  es = es.entity_from_dataframe(
      "sales",
      dataframe=train_df,
      index="sale_id", make_index=True,
      time_index='transacted_date',
  )
  es.normalize_entity(
      new_entity_id="stores",
      base_entity_id="sales",
      index="store_id",
      additional_variables=['region']
  )
  
  # When using a training window, 
  # it is necessary to calculate the last time indexes for the entity set. Adding
  es.add_last_time_indexes()
  
  features  = ft.dfs(
      entityset=es,
      target_entity='stores',
      cutoff_time=data_df,
      verbose=1,
      cutoff_time_in_index=True,
      n_jobs=1,
      max_depth=2,
  
      agg_primitives=["sum",],
      trans_primitives=["cum_max"], 
      training_window="1 month",
  )
  </code></pre>
  
  <p><code>dfs</code> works fine but can not interpret the result features.</p>
  
  <p>And here is the sample data of features:</p>
  
  <p><a href="https://i.stack.imgur.com/gpseb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gpseb.png" alt="enter image description here"></a></p>
  
  <p>As you can see here, the first row of <code>SUM(sales.amount)</code> and <code>SUM(sales.CUM_MAX(amount))</code> are 19, 37 each. I want to know how are they calculated. </p>
  
  <p>Here is how I interpreted the result:</p>
  
  <p><a href="https://i.stack.imgur.com/ht75H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ht75H.png" alt="enter image description here"></a></p>
  
  <ol>
  <li><p>As you can see here, store_0 has 2 records of sale data in Feb, 2012. So, <code>SUM(sales.amount)</code> of store_id=0 on cutoff time of 2012-03-01 should be 0 + 8 = 8, not 19.</p></li>
  <li><p>Likewise, <code>SUM(sales.CUM_MAX(amount))</code>of store_id=0 on cutoff time of 2012-03-01 also should be SUM(sales.CUM_MAX(amount)) = SUM([0, 8]) = 8, not 37.</p></li>
  </ol>
  
  <p>Did I miss anything? How are they calculated?</p>