MlBlock fit function
NajatAbd opened this issue · 5 comments
- MLBlocks version: 0.2.0
- Python version: 3.6
- Operating System: MAC OS
Description
I'm trying to use MLBlock and not MLPipeline and everything was fine, but whenever I want to fit my model the code crashes.
What I Did
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from mlblocks import MLBlock
block = MLBlock('sklearn.svm.SVC')
iris = load_iris()
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=7)
block.fit(X_train, y_train)
#Traceback:
Traceback (most recent call last):
File "<ipython-input-22-7c1505067a70>", line 1, in <module>
runfile('/Users/najat/Documents/GitHub/Cardea/cardea/modeling/modeling.py', wdir='/Users/najat/Documents/GitHub/Cardea/cardea/modeling')
File "/Users/najat/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "/Users/najat/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/Users/najat/Documents/GitHub/Cardea/cardea/modeling/modeling.py", line 30, in <module>
block.fit(X_train, y_train)
TypeError: fit() takes 1 positional argument but 3 were given
Hi @NajatAbd Thanks for reporting this.
It looks like something might be wrong in the primitive JSON. Could you include its contents here?
On another subject, it looks like you are trying to use a primitive that does not exist yet in MLPrimitives. If you finish making it work, please consider opening an issue there and contributing it!
I don't think the problem with the primitive it self, because I used it in MLPipeline and it did work. I even tried another primitive just to make sure and I still get the same error using MLBlocks
Oh, sorry, there was something which I did not spot beforehand: You are using an MLBlock instead of an MLPipeline! This is not the recommended approach, but if you wanted to use an MLBlock directly anyways, you would need to know exactly which arguments your primitive expects and pass them as keyword arguments (named arguments), like this:
mlblock.fit(X=X_train, y=y_train)
But, as I was saying, the recommended usage is going through an MLPipeline, which is the one that truly provides the user friendly interface, as the MLBlock is more suited for internal mlblocks usage.
In this case, your code should look like this:
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from mlblocks import MLPipeline
pipeline = MLPipeline(['sklearn.svm.SVC'])
iris = load_iris()
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=7)
pipeline.fit(X_train, y_train)
Aha now I understood the problem, Thank you!