예제 #1
0
#Linear reggression
[a, b] = linearRegression(Tid, T)
xplot = Tid
yplot = np.dot(a,xplot)+b
plt.plot(xplot, yplot, 'r')
#Determinant koeffisienten
Sy2 = sum((T-np.mean(T))**2)
SSELin = sum((T-np.dot(a,Tid)-b)**2)
r2Linear = (Sy2-SSELin)/Sy2
print('\nLineære regresjon sin determinant koeffisient:')
print(np.sqrt(r2Linear))
#print(np.corrcoef(Tid, T)[0][1])

#Oppgave c
#Quadratic regression
[a, b, c] = quadraticRegression(Tid, T)
yplot = np.dot(a,np.power(xplot,2))+np.dot(b,xplot) + c
plt.plot(xplot, yplot, 'b--')
#Determinant koeffisienten
Sy2 = sum((T-np.mean(T))**2)
SSEQuad = sum((T-(np.dot(a,np.power(Tid,2))+np.dot(b,Tid) + c))**2)
Quadratic = (Sy2-SSEQuad)/Sy2
print('\nKvadratisk regresjon sin determinant koeffisient:')
print(np.sqrt(Quadratic))
#print(np.corrcoef(xplot, yplot)[0][1])

#Cubic regression
[a, b, c, d] = cubicRegression(Tid, T)
yplot = np.dot(a,np.power(xplot,3))+ np.dot(b,np.power(xplot,2))+np.dot(c, xplot) + d
plt.plot(xplot, yplot, 'k')
#Determinant koeffisienten
예제 #2
0
# b)
[a_lin, b_lin] = regression.linearRegression(X, T)

Sy2_lin = sum((T - np.mean(T))**2)
SSE_lin = sum((T - (np.dot(a_lin, X) + b_lin))**2)
R2_lin = (Sy2_lin - SSE_lin) / Sy2_lin

print("Determinantkoeffisient for lineære", R2_lin)  # -> 0.7452554736192584

xplot = np.array(list(range(min(X), max(X))))
yplot = np.dot(xplot, a_lin) + b_lin

plt.plot(xplot, yplot)

# c)
[a_kva, b_kva, c_kva] = regression.quadraticRegression(X, T)

Sy2_kva = sum((T - np.mean(T))**2)
SSE_kva = sum(
    (T - (np.dot(a_kva, np.power(X, 2)) + np.dot(b_kva, X) + c_kva))**2)
R2_kva = (Sy2_kva - SSE_kva) / Sy2_kva

print("Determinantkoeffisient for kvadratisk", R2_kva)  # -> 0.9126314317675248

yplot = np.dot(a_kva, np.power(xplot, 2)) + np.dot(b_kva, xplot) + c_kva

plt.plot(xplot, yplot)

[a_kub, b_kub, c_kub, d_kub] = regression.cubicRegression(X, T)

Sy2_kub = sum((T - np.mean(T))**2)
예제 #3
0
[a, b] = reg.linearRegression(X, T)
# plt.figure(0)

# xplot = np.array(list(range(-1,6))) # litt større område enn x-ene
yplot = np.dot(a, X) + b
plot_lin = plt.plot(X, yplot, label="Linear")

Sy2 = sum((T - np.mean(T))**2)
SSELin = sum((T - np.dot(a, X) - b)**2)
r2Linear = (Sy2 - SSELin) / Sy2
print("\n2b)\nr² = ", r2Linear)

# c)

# Kvadratisk tilnærming:
[a, b, c] = reg.quadraticRegression(X, T)  # så kvadratisk
yplot = np.dot(a, np.power(X, 2)) + np.dot(b, X) + c
plot_qua = plt.plot(X, yplot, label="Quadratic")
SSEQuad = sum((T - (np.dot(a, np.power(X, 2)) + np.dot(b, X) + c))**2)
r2Quadratic = (Sy2 - SSEQuad) / Sy2

print("\nc)\nKvadratisk tilnærming r² = ", r2Quadratic)

# Kubisk tilnærming:
[a, b, c, d] = reg.cubicRegression(X, T)
yplot = np.dot(a, np.power(X, 3)) + np.dot(b, np.power(X, 2)) + np.dot(c,
                                                                       X) + d
plot_cubic = plt.plot(X, yplot, label="Cubic")
SSECubic = sum((T - (np.dot(a, np.power(X, 3)) + np.dot(b, np.power(X, 2)) +
                     np.dot(c, X) + d))**2)
r2Cubic = (Sy2 - SSECubic) / Sy2
예제 #4
0
# b)

[a, b] = linearRegression(tid, temp)
xplot = np.array(list(range(0, 60)))
yplot = np.dot(a, xplot) + b
plt.plot(xplot, yplot)

Sy2 = sum((temp - np.mean(temp))**2)
SSELin = sum((temp - np.dot(a, tid) - b)**2)
r2Linear = (Sy2 - SSELin) / Sy2

# Determinasjonskoeffisienten = 0.745

# c)

[a, b, c] = quadraticRegression(tid, temp)
yplot = np.dot(a, np.power(xplot, 2)) + np.dot(b, xplot) + c
plt.plot(xplot, yplot)

SSEQuad = sum((temp - (np.dot(a, np.power(tid, 2)) + np.dot(b, tid) + c))**2)
r2Quadratic = (Sy2 - SSEQuad) / Sy2

# Determinasjonskoeffisienten ved kvadratisk tilnærming = 0.913

[a, b, c, d] = cubicRegression(tid, temp)
yplot = np.dot(a, np.power(xplot, 3)) + np.dot(b, np.power(xplot, 2)) + np.dot(
    c, xplot) + d
plt.plot(xplot, yplot)

SSECubic = sum((temp - (np.dot(a, np.power(tid, 3)) +
                        np.dot(b, np.power(tid, 2)) + np.dot(c, tid) + d))**2)
예제 #5
0
omega = data["omega"][0][0].astype(float)

# 1a - Se 1a.png for figur
# Linear regression
[a, b] = regression.linearRegression(x, y)
plt.figure(0)
plt.scatter(x, y)
xplot = np.linspace(-2, 12)
yplot = np.dot(a, xplot) + b
plt.plot(xplot, yplot)
Sy2 = sum((y - np.mean(y))**2)
SSELin = sum((y - np.dot(a, x) - b)**2)
r2Linear = (Sy2 - SSELin) / Sy2

# Quadratic regression
[a, b, c] = regression.quadraticRegression(x, y)
yplot = np.dot(a, np.power(xplot, 2)) + np.dot(b, xplot) + c
plt.plot(xplot, yplot)
SSEQuad = sum((y - (np.dot(a, np.power(x, 2)) + np.dot(b, x) + c))**2)
r2Quadratic = (Sy2 - SSEQuad) / Sy2

# Cubic regression
[a, b, c, d] = regression.cubicRegression(x, y)
yplot = np.dot(a, np.power(xplot, 3)) + np.dot(b, np.power(xplot, 2)) + np.dot(
    c, xplot) + d
plt.plot(xplot, yplot)
SSECubic = sum((y - (np.dot(a, np.power(x, 3)) + np.dot(b, np.power(x, 2)) +
                     np.dot(c, x) + d))**2)
r2Cubic = (Sy2 - SSECubic) / Sy2
omega = 8