0
import pandas as pd
import numpy as np
data = pd.read_csv("SuperMarketSales.csv")
x = data.iloc[:,0:5] #features
y = data.iloc[:,5:6] #results
months = pd.DatetimeIndex(data['Date'], dayfirst=True).month
x.iloc[: , 1:2] = months
w = np.array([[0],[0],[0],[0],[0]])
def derivs(X,W,Y,B):
    m,n = X.shape
    dj_dw = np.zeros(m)
    dj_db = 0
    for i in range(m):
        dott = np.dot(X.iloc[i:i+1],W)
        error = (dott[0] + B) - Y.iloc[i]
        for j in range(n):
            current = np.dot(X.iloc[i:i + 1, j:j + 1], 1)
            dj_dw[j] = dj_dw[j] + int(error) * current
        dj_db = dj_db + int(error)
    dj_dw = dj_dw / m
    dj_db = dj_db / m
    return dj_dw , dj_db


b = 0.0
rate = 0.0000001
epochs = 100
for i in range(epochs):
    print("epoch")
    dj_dw , dj_db = derivs(x,w,y,b)
    w = w - rate * dj_dw
    b = b - rate * dj_db


print(f'final w is {w} and final b is {b}')

i keep getting

ValueError: Length of values (6435) does not match length of index (1)

this is not the first error i got, I got way too many but I can't resolve this one because I don't understand why it is happening, I understand why it happens regularly but not in my code noq

desertnaut
  • 57,590
  • 26
  • 140
  • 166

0 Answers0