Ich versuche, ein Modell auf einen Datensatz eines Features in Spalte 1 und einen Vektor in Spalte 0 angehängt. Egal was ich versuche, Kurve passt schlecht zu den Daten.lineares Regressionsmodell passt schlecht
Hier ist der Code.
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
col = ['id','ri','na','mg','al','si','k','ca','ba','fe','glass_type']
data = pd.read_csv('glass.data', names=col, index_col='id')
x = np.array(data)[:, 0]
x = x.reshape(np.size(x), 1)
y = np.array(data)[:, 3]
y = y.reshape(np.size(y), 1)
# initialising
m = np.size(x)
# appending ones vector in x
one = np.ones([m, 1], dtype=float)
x1 = np.append(one, x, axis=1)
# weight matrix
theta = np.zeros([2, 1])
i_list = []
j_l = []
error = np.zeros([m, 1])
# gradient descent
for i in range(3500):
h = x1.dot(theta)
error = h - y
theta = theta - (0.0001/m) * np.sum(x1.T.dot(error)) + (1.5/m) * np.sum(np.sum((theta[:, 1:2])**2))
i_list.append(i)
j = (1/(2*m)) * np.sum((h-y)**2)
j_l.append(j)
# plotting
plt.subplot(1, 2, 1)
plt.plot(x, y, '.r')
plt.plot(x, x1.dot(theta), '-b')
plt.subplot(1,2, 2)
plt.plot(i_list, j_l, '-g')
plt.show()
This how the data fits (image) mir bitte Möglichkeiten aufzeigen, um es zu verbessern. Danke :)
Diese Daten sieht nicht wie eine Linie kann es passen. Es scheint wenig bis keine Korrelation zu haben und es gruppiert sich um diesen Punkt in der Mitte. Versuchen Sie, die Parameter, die Sie eingeben, oder das Regressionsmodell zu ändern. – Primusa
@primusa Ich benutze Scikit lernen, die Daten anzupassen und es war sehr gut geeignet. – quantumbiker