Reading the Scikit-Learn Documentation.
Relationship to scikit-learn
ScikitLearn.jl aims to mirror the Python scikit-learn project, but the API had to be adapted to Julia, and follows Julia's conventions. When reading the Python documentation, keep in mind:
- Most object methods are now functions: Python's
model.predict(X)
becomespredict(model, X)
- Methods that modify the model's state have a
!
at the end:model.fit_transform(X)
becomesfit_transform!(model, X)
- A few of the Python submodules were translated into Julia to support Julia models:
ScikitLearn.Pipelines
,ScikitLearn.CrossValidation
, andScikitLearn.GridSearch
You can access the class members and methods of a Python object (i.e. all models imported through @sk_import
) using obj.member_name
. For example:
julia> X=rand(10,4);y=rand(10);
julia> @sk_import linear_model: Lasso
PyObject <class 'sklearn.linear_model._coordinate_descent.Lasso'>
julia> lm = fit!(Lasso(), X, y)
PyObject Lasso(alpha=1.0, copy_X=True, fit_intercept=True, max_iter=1000,
normalize=False, positive=False, precompute=False, random_state=None,
selection='cyclic', tol=0.0001, warm_start=False)
julia> println(lm.n_iter_)
1
This is rarely necessary, because the most important/frequently-used methods have been defined in Julia (eg. transformer.classes_
is now get_classes(transformer)
)