Генералов Кирилл N2
Материал из Wiki
Версия от 17:16, 7 июня 2019; Генералов Кирилл (обсуждение | вклад)
import numpy as np import math f = open("order.txt", "r") X = [] Y = [] for line in f:
q, x1, x2, x3, x4, x5, x6, y = map(float, line.split()) x = [] x.append(x1) x.append(x2) x.append(x3) x.append(x4) x.append(x5) x.append(x6) x.append(x1 * x1) x.append(x1 * x2) x.append(x1 * x3) x.append(x1 * x4) x.append(x1 * x5) x.append(x1 * x6) x.append(x2 * x2) x.append(x2 * x3) x.append(x2 * x4) x.append(x2 * x5) x.append(x2 * x6) x.append(x3 * x3) x.append(x3 * x4) x.append(x3 * x5) x.append(x3 * x6) x.append(x4 * x4) x.append(x4 * x5) x.append(x4 * x6) x.append(x5 * x5) x.append(x5 * x6) x.append(x6 * x6) X.append(x) Y.append(y)
f.close() Mx = [] for j in range(27):
Mx1 = np.sum(X[j]) / len(X) Mx.append(Mx1)
My = np.sum(Y)/len(Y) print(Mx) print("Мат.ожидание(Mx) =", Mx) Dx = [] Dx11 = 0 Dy = 0
for i in range(len(X)):
Dy += (Y[i] - My) ** 2
for i in range(27):
Dxs = 0.0 for j in range(len(X)): Dxs += (X[j][i] - Mx[i]) ** 2 print(Dxs)
Dx.append(Dxs/len(X))
print("Дисперсия(Dx) = ", Dx) kx = [] for i in range(27):
kxs = 0.0 for j in range(len(X)): kxs += ((X[j][i] - Mx[i]) * (Y[j] - My)) kx.append(kxs)
print("Коэффициент корреляции (kx)=", kx) r = [] rABS = [] for i in range(len(kx)):
r1 = (kx[i] / (len(X)-1)) / (math.sqrt(Dx[i]) * math.sqrt(Dy)) r.append(r1) rABS.append(math.fabs(r1))
print("r =", r) print(np.max(rABS)) print("Первый индекс = ", rABS.index(np.max(rABS)) + 1)