0

I have dataframe

weight height 56 167 88 179 42 159 51 162 90 170 

And I try to apply some function

def min_error(w0, w1, height, weight): return np.sum(np.power((height - (w0 + w1*weight))), 2) (data.apply(lambda row: min_error(60, 0.05, row['Height'], row['Weight']), axis=1)) 

But it returns

ValueError: ('invalid number of arguments', u'occurred at index 1')

How can I fix that?

3 Answers 3

1

The problem is your call to np.power. You have the parenthesis in the wrong place. Try:

def min_error(w0, w1, height, weight): return np.sum(np.power((height - (w0 + w1*weight)), 2)) 

The problem is not with Pandas, but it was identified at a Pandas index, so it appeared to be an error with data.apply, which it isn't.

Sign up to request clarification or add additional context in comments.

Comments

0

Your math formula is incorrect. What is happening here is that np.power expects two arguments but is only receiving 1. Check your parenthesis.

I think this is the formula you want:

def min_error(w0, w1, height, weight): return np.sum(np.power((height - (w0 + w1*weight)),2)) (data.apply(lambda row: min_error(60, 0.05, row['height'], row['weight']), axis=1)) 

Output:

0 10857.6400 1 13133.1600 2 9389.6100 3 9890.3025 4 11130.2500 dtype: float64 

Comments

0

maybe this will help you too.

df['min_error']=min_error(60, 0.05, df['height'], df['weight']) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.