34 lines
825 B
Python
34 lines
825 B
Python
|
# import numexpr as ne
|
||
|
import numpy as np
|
||
|
|
||
|
with open("dataset/small_data.csv", "r") as f:
|
||
|
desc = f.readline().strip()
|
||
|
rows, dimensions = map(int, desc.split(" "))
|
||
|
data = np.loadtxt(f)
|
||
|
print("loaded data")
|
||
|
|
||
|
with open("dataset/small_label.csv", "r") as f:
|
||
|
desc = f.readline().strip()
|
||
|
rows = int(desc)
|
||
|
labels = np.loadtxt(f)
|
||
|
print("loaded labels")
|
||
|
|
||
|
print(data.shape)
|
||
|
print(labels.shape)
|
||
|
|
||
|
w = np.empty((dimensions, 1))
|
||
|
new_w = np.empty(w.shape)
|
||
|
for _ in range(10):
|
||
|
for i in range(dimensions):
|
||
|
data_ni = np.delete(data, i, axis=1)
|
||
|
w_ni = np.delete(w, i)
|
||
|
|
||
|
res = data_ni @ w_ni
|
||
|
|
||
|
x_i = data[:,i]
|
||
|
numer = x_i.transpose() @ (labels - np.matmul(data_ni, w_ni))
|
||
|
denom = x_i.transpose() @ x_i
|
||
|
|
||
|
new_w[i] = numer / denom
|
||
|
w = new_w
|
||
|
print("w", new_w)
|