Search code examples
kdb

Positional arguments with embedpy on KDB


\l p.q

np:.p.import`numpy
Logistic:.p.import[`sklearn.linear_model;`:LogisticRegression]

train_X_np: np[`:array](1 2 3)
train_Y_np: np[`:array](0 1 1)

Logistic[`:fit][train_X_np;train_Y_np]

When I run this I get:

call: fit() missing 1 required positional argument: 'y'

What am I doing wrong?

(Also normally, there should be a .reshape(-1,1) on the X array, I wonder if this is the cause?)


Solution

    • You need to initialise the LogisticRegression object

    • You need to reshape the x input

      q)Logistic:.p.import[`sklearn.linear_model;`:LogisticRegression][]
      q)train_X_np: np[`:array][1 2 3][`:reshape;-1 1]
      q)Logistic[`:fit][train_X_np;train_Y_np]
      / To predict
      q)Logistic[`:predict][np[`:array][0 1 2][`:reshape;-1 1]]`
      0 1 1
      

    You could also use flip enlist 1 2 3 kdb list before passing it to numpy instead of reshaping