def plot_components(self, X_true=None, y_true=None, groups=None, fig=None):
        import matplotlib.pyplot as plt

        if fig is None:
            fig = plt.figure(figsize=(18, 1))

        lookahead_scale = 0.3
        t_min, t_max = self._X_scaler_.min_["t"], self._X_scaler_.max_["t"]
        t_max += (t_max - t_min) * lookahead_scale
        t = pd.date_range(t_min, t_max, freq="D")

        scaled_t = np.linspace(0, 1 + lookahead_scale, len(t))
        total = self.plot(self.trace_, scaled_t, self._y_scaler_)

        ax = add_subplot()
        ax.set_title("overall")
        ax.plot(t, self._y_scaler_.inv_transform(total))

        if X_true is not None and y_true is not None:
            if groups is not None:
                for group in groups.cat.categories:
                    mask = groups == group
                    ax.scatter(
                        X_true["t"][mask],
                        y_true[mask],
                        label=group,
                        marker=".",
                        alpha=0.2,
                    )
            else:
                ax.scatter(X_true["t"], y_true, c="k", marker=".", alpha=0.2)
        fig.tight_layout()
        return fig
Beispiel #2
0
    def plot(self, trace, scaled_t, y_scaler):
        scaled_s = pd.Series(self._predict(trace, scaled_t).mean(axis=1), name='value')
        s = y_scaler.inv_transform(scaled_s)

        ax = add_subplot()
        ax.set_title(str(self))
        ax.set_xticks([])
        ax.plot(scaled_t, s, c="lightblue")
        return scaled_s
Beispiel #3
0
    def plot(self, trace, scaled_t, y_scaler):
        ax = add_subplot()
        ax.set_title(str(self))
        trend_return = np.empty((len(scaled_t), len(self.groups_)))
        plot_data = []
        for group_code, group_name in self.groups_.items():
            y_hat = np.mean(self._predict(trace, scaled_t, group_code), axis=1)
            trend_return[:, group_code] = y_hat
            plot_data.append((group_name, y_hat[0]))
        ax.bar(*zip(*plot_data))
        ax.axhline(0, c="k", linewidth=3)

        return trend_return
    def plot(self, trace, scaled_t, y_scaler):
        ax = add_subplot()

        scaled_trend = self._predict(trace, scaled_t)
        trend = y_scaler.inv_transform(scaled_trend)

        ax.set_title(str(self))
        ax.set_xticks([])
        ax.plot(scaled_t, trend.mean(axis=1), c="lightblue")
        for changepoint in self.s:
            ax.axvline(changepoint, linestyle="--", alpha=0.2, c="k")

        return scaled_trend.mean(axis=1)
Beispiel #5
0
 def plot(self, trace, scaled_t, y_scaler):
     ax = add_subplot()
     ax.set_title(str(self))
     ax.set_xticks([])
     trend_return = np.empty((len(scaled_t), len(self.groups_)))
     for group_code, group_name in self.groups_.items():
         y_hat = mode(self._predict(trace, scaled_t, group_code),
                      axis=1)[0][:, 0]
         ax.plot(scaled_t, y_hat, label=group_name)
         trend_return[:, group_code] = y_hat
     ax.set_ylim([-1.05, 1.05])
     ax.legend()
     return trend_return
Beispiel #6
0
    def plot(self, trace, scaled_t, y_scaler):
        ax = add_subplot()
        ax.set_title(str(self))

        seasonality_return = np.empty((len(scaled_t), len(self.groups_)))
        for group_code, group_name in self.groups_.items():
            scaled_s = self._predict(trace, scaled_t, group_code)
            s = y_scaler.inv_transform(scaled_s)
            ax.plot(list(range(self.period.days)), s.mean(axis=1)[:self.period.days], label=group_name)

            seasonality_return[:, group_code] = scaled_s.mean(axis=1)

        return seasonality_return
Beispiel #7
0
    def plot(self, trace, scaled_t, y_scaler):
        ax = add_subplot()
        ax.set_title(str(self))
        ax.set_xticks([])
        trend_return = np.empty((len(scaled_t), len(self.groups_)))
        for group_code, group_name in self.groups_.items():
            scaled_trend = self._predict(trace, scaled_t, group_code)
            trend = y_scaler.inv_transform(scaled_trend)
            ax.plot(scaled_t, trend.mean(axis=1), label=group_name)
            trend_return[:, group_code] = scaled_trend.mean(axis=1)

        for changepoint in self.s:
            ax.axvline(changepoint, linestyle="--", alpha=0.2, c="k")
        ax.legend()
        return trend_return