hyperopt / hyperopt-sklearn

Hyper-parameter optimization for sklearn

Home Page:hyperopt.github.io/hyperopt-sklearn

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why this code won't work?

pavpatel677 opened this issue · comments

 def calcScore(x,y):
   if prem['FTHG'] > prem['FTAG']:
    x = 3
    y = 0
   elif prem['FTHG'] == prem['FTAG']:
    x = 1 
    y = 1
   else:
    x = 0
    y = 3
    
return x,y



 prem.iloc[0,:].apply(calcScore)

 calcScore() missing 1 required positional argument: 'y'

I have spent ages on this and it won't work. I am trying to assign 3 points to the winning team and losing team by using the goals shown on the dataframe. I can't see to get it write as I keep on the error shown above, positional argument. Help would be a god send

This doesn't have anything to do with hyperopt-sklearn. You'll have better luck asking these sorts of questions on stackoverflow.

To help point you in the right direction, your calcScore function needs to take only 1 parameter. It will end up being a list when there are multiple columns. Try something like this:

 def calcScore(p):
   if p[0] > p[1]:
    x = 3
    y = 0
   elif p[0] == p[1]:
    x = 1 
    y = 1
   else:
    x = 0
    y = 3
    
return x,y

print(prem[['FTHG','FTHA']].apply(calcScore, axis=1))

This will give you what you are looking for, but the output will be a tuple (x, y) in a single column. One simple way to get around that is to have two calcScore functions, one for x, and one for y.