From fce98b683c6b8cb886d612af900ffde61152686c Mon Sep 17 00:00:00 2001 From: Maxim Slipenko <no-reply@maxim.slipenko.com> Date: Thu, 22 Feb 2024 15:01:30 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20prediction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- statapp/calculations.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/statapp/calculations.py b/statapp/calculations.py index 0429549..a0f9064 100644 --- a/statapp/calculations.py +++ b/statapp/calculations.py @@ -113,8 +113,7 @@ def linearPolynom(data): monomials = ['c'] + ['x' + str(i) for i in range(1, x.shape[1] + 1)] residualVariance = np.var(residuals, ddof=k) - scaledResidualVariance = (residualVariance / - np.mean(residuals) ** 2) if np.mean(residuals) != 0 else np.nan + scaledResidualVariance = residualVariance / (n - k) paramsAndTStats = np.vstack((params, tStats)).T @@ -163,9 +162,7 @@ def squaredPolynom(data): monomials = [monomial.replace(' ', '*') for monomial in monomials] residualVariance = np.var(residuals, ddof=k) - scaledResidualVariance = ( - residualVariance / np.mean(residuals) ** 2 - ) if np.mean(residuals) != 0 else np.nan + scaledResidualVariance = residualVariance / (n - k) paramsAndTStats = np.vstack((params, tStats)).T @@ -194,8 +191,12 @@ def prediction(inputData, result: RegressionResult): results = [] + numVars = inputs.shape[1] + symbolsStr = ' '.join([f'x{i}' for i in range(1, numVars + 1)]) + symbols = sp.symbols(symbolsStr) + for y, xValues in zip(outputs, inputs): - subsDict = dict(zip(expr.free_symbols, xValues)) + subsDict = dict(zip(symbols, xValues)) predictedResult = expr.subs(subsDict) difference = predictedResult - y