def generate_report_bernoulligm(self, mdl, t_train, x0_train, t_test, x0_test): if (mdl.is_fitted == True): t_all = np.concatenate((t_train, t_test), axis=0) x_all = np.concatenate((x0_train, x0_test), axis=0) x_pred = mdl.predict(t_all) lens = len(mdl.x_orig) err = x_pred[:lens] - mdl.x_orig m = len(t_train) x0_train = x_all[:m] x0_test = x_all[m - 1:] t_train = t_all[:m] t_test = t_all[m - 1:] rmse = np.sqrt(sum((err)**2 / lens)) rmse = np.round(rmse, 4) t3 = np.arange(lens) + 1 p = plt.figure() plt.subplot(2, 1, 1) plt.plot(t_train, x0_train) plt.plot(t_train, x_pred[:m]) plt.plot(t_test, x0_test) plt.plot(t_test, x_pred[m - 1:lens]) plt.axvline(x=m, ls="--", lw=1, c='k') plt.legend([ 'x_orig_models', 'x_pred_models', 'x_orig_detected', 'x_pred_detected' ]) plt.axvline(x=m, ls="--", lw=1, c='k') plt.subplot(2, 1, 2) plt.stem(t3, err, linefmt="c:", markerfmt="o", basefmt="r-") plt.axvline(x=m, ls="--", lw=1, c='k') # 打印报告 x1 = Accumulation.ago(mdl.x_orig, None, True) x1_pred = Accumulation.ago(x_pred, None, True) model_report = pd.DataFrame({ 'x_orig': mdl.x_orig, 'x1': x1, 'x1_pred': x1_pred, 'x_pred': x_pred, 'error': err, }) # 公式表达 eq = generate_report.formula_expression_bernoulligm(None, mdl) c1 = [p, model_report, eq] return c1 else: t = np.concatenate((t_train, t_test), axis=1) x0 = np.concatenate((x0_train, x0_test), axis=1) mdl.fit(t, x0) generate_report.generate_report_bernoulligm( mdl, t_train, x0_train, t_test, x0_test)
def generate_report(self, mdl, y_train, t_x_train, y_test, t_x_test, **kwargs): if (mdl.is_fitted == True): y_all = np.concatenate((y_train, y_test), axis=0) t_x = np.concatenate((t_x_train, t_x_test), axis=0) y_pred = mdl.predict(t_x) t_all = t_x[0:, 0] lens = len(mdl.x_orig) m = len(y_train) err = y_pred[:lens] - mdl.x_orig y0_train = y_all[:m] y0_test = y_all[m-1:] t_train = t_all[:m] t_test = t_all[m - 1:] rmse = np.sqrt(sum((err) ** 2 / lens)) rmse = np.round(rmse, 4) t3 = np.arange(lens) + 1 p = plt.figure() plt.subplot(2, 1, 1) plt.plot(t_train, y0_train) plt.plot(t_train, y_pred[:m]) plt.plot(t_test, y0_test) plt.plot(t_test, y_pred[m - 1:lens]) plt.axvline(x=m, ls="--", lw=1, c='k') plt.legend(['x_train', 'x_pred_train', 'x_test', 'x_pred_test']) plt.axvline(x=m, ls="--", lw=1, c='k') plt.title('Model and Test') plt.subplot(2, 1, 2) plt.stem(t3, err, linefmt="c:", markerfmt="o", basefmt="r-") plt.title('RMSE = {}'.format(rmse)) plt.axvline(x=m, ls="--", lw=1, c='k') y1 = Accumulation.ago(y_all, None, True) y1_pred = Accumulation.ago(y_pred, None, True) model_report = pd.DataFrame({ 'x_orig': mdl.x_orig, 'x1': y1, 'x1_pred': y1_pred, 'x_pred': y_pred, 'error': err, }) c1 = [p, model_report] return c1 else: y = np.concatenate((y_train, y_test), axis=0) t_x = np.concatenate((t_x_train, t_x_test), axis=0) mdl.fit(y, t_x) Generate_report_agon.generate_report(None, mdl, y_train, t_x_train, y_test, t_x_test)
def fit(self, y): x1 = Accumulation.ago(y, None, True) z1 = ModelMethods.get_backvalue(x1) z1_square = np.power(z1, self.n) B = ModelMethods.construct_matrix(z1, z1_square) self.x_orig = y self.params = ModelMethods.get_params(B, y) return self
def fit(self, x, y): x1 = Accumulation.ago(y, None, True) z1 = ModelMethods.based(x1) ones_array = np.diff(x).astype(np.float64) ones_array = ones_array.reshape([-1, 1]) B = ModelMethods.construct_matrix(-z1, ones_array) self.x_orig = y self.params = ModelMethods.get_params(B, x1) return self
def fit(self, x, y): x1 = Accumulation.ago(y, None, True) z1 = ModelMethods.get_backvalue(x1) arange_array = x[1:] arange_array = arange_array.reshape([-1, 1]) B = ModelMethods.construct_matrix(z1, arange_array) self.x_orig = y self.params = ModelMethods.get_params(B, y) return self
def fit(self, x, y): x1 = Accumulation.ago(y, None, True) z1 = ModelMethods.get_backvalue(x1) ones_array = np.diff(x).astype(np.float64) ones_array = ones_array.reshape([-1, 1]) self.B = ModelMethods.construct_matrix(z1, ones_array) self.x_orig = y self.params = ModelMethods.get_params(self.B, y) self.is_fitted = True return self
def fit(self, x, y): x1 = Accumulation.ago(y, None, True) z1 = ModelMethods.based(x1) ones_array = np.diff(x).astype(np.float64) ones_array = ones_array.reshape([-1, 1]) range_array = np.arange(len(x) - 1) range_array = range_array.reshape([-1, 1]) B1 = ModelMethods.construct_matrix(-z1, range_array) self.B = ModelMethods.construct_matrix(-B1, ones_array) self.x_orig = y self.params = ModelMethods.get_params(self.B, x1) self.x1 = x1 self.is_fitted = True return self
def predict(self, t): all_t = np.arange(0, np.max(t)) x1_pred = _res_func_list.res_funcs[self.mdl_name].compute( self.params, all_t, self.x_orig[0]) x_pred = Accumulation.ago(x1_pred, self.x_orig[0], False) return x_pred