Linear regression : ValueError: operands could not be broadcast together with shapes (3,) (1338,)
I try to use linear regression for insurance data . But had error on the when try to call a function with features parameter. Here is my code:
def h(x):
global w
return np.sum(np.transpose(w)*x)
raise NotImplementedError()
when try with a simple data it works fine,
w, x = [1,2,3], [2,3,4]
h(x)
the output is : 20
but when try to use the dataset, it errors:
features = dataset.drop(["charges"], axis=1).values
h(features )
it returns error:
ValueError: operands could not be broadcast together with shapes (3,) (1338,)
so the features looks like this:
array([[0.1173913 , 0. , 0.35698144, 0. , 1. ],
[0.1 , 1. , 0.48331988, 1. , 0. ],
[0.27391304, 1. , 0.46674738, 3. , 0. ],
...,
[0.1 , 0. , 0.5496099 , 0. , 0. ],
[0.15217391, 0. , 0.3117837 , 0. , 0. ],
[0.84782609, 0. , 0.38216303, 0. , 1. ]])
The data i used is insurance.csv from kaggle.com
Topic implementation linear-regression python machine-learning
Category Data Science