User Guide ๐
As introduced in the home page , sklearn-smithy is a tool that helps you to forge scikit-learn compatible estimator with ease, and it comes in three flavours.
Let's see how to use each one of them.
Web UI ๐
TL;DR:
The web UI is the most user-friendly, low barrier way, to interact with the tool by accessing it directly from your browser, without any installation required.
Once the estimator is forged, you can download the script with the code as a .py
file, or you can copy the code directly from the browser.
Screenshot
CLI โจ๏ธ
TL;DR:
Once the library is installed, the smith
CLI (Command Line Interface) will be available and that is the primary way to interact with the smithy
package.
The CLI provides a main command called forge
, which will prompt a series of question in the terminal, based on which it will generate the code for the estimator.
smith forge
example
Let's see an example of how to use smith forge
command:
$ <font color = "#4E9A06" >smith</font> forge
# ๐ How would you like to name the estimator?:$ MightyClassifier
# ๐ฏ Which kind of estimator is it? ( classifier, outlier, regressor, transformer, cluster, feature-selector) :$ classifier
# ๐ Please list the required parameters ( comma-separated) [] :$ alpha,beta
# ๐ Please list the optional parameters ( comma-separated) [] :$ mu,sigma
# ๐ถ Does the ` .fit() ` method support ` sample_weight` ? [ y/N] :$ y
# ๐ Is the estimator linear? [ y/N] :$ N
# ๐ฒ Should the estimator implement a ` predict_proba` method? [ y/N] :$ N
# โ Should the estimator implement a ` decision_function` method? [ y/N] :$ y
# ๐งช We are almost there... Is there any tag you want to add? ( comma-separated) [] :$ binary_only,non_deterministic
# ๐ Where would you like to save the class? [ mightyclassifier.py] :$ path/to/file.py
<span style="color: green; font-weight: bold;">Template forged at path/to/file.py </span>
Now the estimator template to be filled will be available at the specified path path/to/file.py
.
$ cat path/to/file.py | head -n 5
import numpy as np
from sklearn.base import BaseEstimator, ClassifierMixin
from sklearn.utils import check_X_y
from sklearn.utils.validation import check_is_fitted, check_array
Non-interactive mode
As for any CLI, in principle it would be possible to run it in a non-interactive way, however this is not fully supported (yet) and it comes with some risks and limitations.
The reason for this is that the validation and the parameters interaction happen while prompting the questions one after the other , meaning that the input to one prompt will determine what follows next.
It is still possible to run the CLI in a non-interactive way, but it is not recommended, as it may lead to unexpected results.
Let's see an example of how to run the smith forge
command in a non-interactive way:
Non-interactive mode
smith forge \
--name MyEstimator \
--estimator-type classifier \
--required-params "a,b" \
--optional-params "" \
--no-sample-weight \
--no-predict-proba \
--linear \
--no-decision-function \
--tags "binary_only" \
--output-file path/to/file.py
Notice how all arguments must be specified, otherwise they will prompt anyway, which means that the command would be interactive.
Secondly, there is nothing preventing us to run the command with contradictory arguments at the same time. Operating in such a way can lead to two scenarios:
The result will be correct, however unexpected from a user point of view.
For instance, calling --estimator-type classifier
with --linear
and --decision-function
flags, will not create a decision_function
method, as LinearClassifierMixin
already takes care of it.
The result will be incorrect, as the arguments are contradictory.
The first case is not a problematic from a functional point of view, while the second will lead to a broken estimator.
Our suggestion is to use the CLI always in an interactive way, as it will take care of the proprer arguments interaction.
TUI ๐ป
TL;DR:
If you like the CLI, but prefer a more interactive and graphical way from the comfort of your terminal, you can use the TUI (Terminal User Interface) provided by the smith forge-tui
command.
Scikit-learn Smithy โ๏ธ
v0.2.0 Scikit-learn Smithy โ๏ธ
๐ How would you like to name the estimator? ๐ฏ Which kind of estimator is it?
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ MightyEstimator โ โ Select โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
๐ Please list the required parameters (comma-separated) ๐ Please list the optional parameters (comma-separated)
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ alpha,beta โ โ mu,sigma โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโ โ โ โโโโโโโโ โ
โ โ ๐ถ Does the `.fit()` method support `sample_weight`? โ โ ๐ Is the estimator linear?
โ โโโโโโโโ โ โ โโโโโโโโ โ
โ โโโโโโโโ โ โ โโโโโโโโ โ
โ โ ๐ฒ Should the estimator implement a `predict_proba` method? โ โ โ Should the estimator implement a `decision_function` method?
โ โโโโโโโโ โ โ โโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
Forge โ๏ธ Save ๐ โ ๐ Where would you like to save the class? โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โถ Code Editor
^d Description L Light/Dark mode F Forge ^s Save E Exit