Package: poniard
PoniardIntroductionA poniard /ˈpɒnjərd/ or poignard (Fr.) is a long, lightweight
thrusting knife (Wikipedia).Poniard is a scikit-learn companion library that streamlines the process
of fitting different machine learning models and comparing them.It can be used to provide quick answers to questions like these: * What
is the reasonable range of scores for this task? * Is a simple and
explainable linear model enough or should I work with forests and
gradient boosters? * Are the features good enough as is or should I
work on feature engineering? * How much can hyperparemeter tuning
improve metrics? * Do I need to work on a custom preprocessing
strategy?This is not meant to be end to end solution, and you definitely should
keep on working on your models after you are done with Poniard.The core functionality has been tested to work on Python 3.7 through
3.10 on Linux systems, and from 3.8 to 3.10 on macOS.InstallationStable version:pipinstallponiardDev version with most up to date changes:pipinstallgit+https://github.com/rxavier/poniard.git@develop#egg=poniardDocumentationCheck the fullQuarto docs,
including guides and API reference.Usage/featuresBasicsThe API was designed with tabular tasks in mind, but it should also work
with time series tasks provided an appropiate cross validation strategy
is used (don’t shuffle!)The usual Poniard flow is: 1. Define some estimators. 2. Define some
metrics. 3. Define a cross validation strategy. 4. Fit everything. 5.
Print the results.Poniard provides sane defaults for 1, 2 and 3, so in most cases you can
just do…fromponiardimportPoniardRegressorfromsklearn.datasetsimportload_diabetesX,y=load_diabetes(return_X_y=True,as_frame=True)pnd=PoniardRegressor(random_state=0)pnd.setup(X,y)pnd.fit()<h2>Setup info</h2>
                     <h3>Target</h3>
                         <p><b>Type:</b> continuous</p>
                         <p><b>Shape:</b> (442,)</p>
                         <p><b>Unique values:</b> 214</p>
                         <h3>Metrics</h3>
                         <b>Main metric:</b> neg_mean_squared_errorFeature type inferenceMinimum unique values to consider a number-like feature numeric:44Minimum unique values to consider a categorical feature high cardinality:20Inferred feature types:numericcategorical_highcategorical_lowdatetime0agesex1bmi2bp3s14s25s36s47s58s60%|          | 0/9 [00:00<?, ?it/s]

PoniardRegressor(random_state=0)… and get a nice table showing the average of each metric in all folds
for every model, including fit and score times (thanks, scikit-learncross_validatefunction!)pnd.get_results()test_neg_mean_squared_errortest_neg_mean_absolute_percentage_errortest_neg_median_absolute_errortest_r2fit_timescore_timeLinearRegression-2977.598515-0.396566-39.0091460.4891550.0052650.001960ElasticNet-3159.017211-0.422912-42.6195460.4607400.0035090.001755RandomForestRegressor-3431.823331-0.419956-42.2030000.4145950.1014350.004821HistGradientBoostingRegressor-3544.069433-0.407417-40.3963900.3916330.3346950.009266KNeighborsRegressor-3615.195398-0.418674-38.9800000.3796250.0030380.002083XGBRegressor-3923.488860-0.426471-39.0313090.3299610.0556960.002855LinearSVR-4268.314411-0.374296-43.3885920.2714430.0034700.001721DummyRegressor-5934.577616-0.621540-61.775921-0.0007970.0030100.001627DecisionTreeRegressor-6728.423034-0.591906-59.700000-0.1454600.0041790.001667Alternatively, you can also get a nice plot of your different metrics by
using thePoniardBaseEstimator.plot.metricsmethod.Type inferencePoniard uses some basic heuristics to infer the data types.Float and integer columns are defined as numeric if the number of unique
values is greater than indicated by thecategorical_thresholdparameter.String/object/categorical columns are assumed to be categorical.Datetime features are processed separately with a custom encoder.For categorical features, high and low cardinality is defined by thecardinality_thresholdparameter. Only low cardinality categorical
features are one-hot encoded.EnsemblesPoniard makes it easy to combine various estimators in stacking or
voting ensembles. The base esimators can be selected according to their
performance (top-n) or chosen by their names.Poniard also reports how similar the predictions of the estimators are,
so ensembles with different base estimators can be built. A basic
correlation table of the cross-validated predictions is built for
regression tasks, whileCramér’s
Vis used for
classification.By default, it computes this similarity of prediction errors instead of
the actual predictions; this helps in building ensembles with good
scoring estimators and uncorrelated errors, which in principle and
hopefully should lead to a “wisdom of crowds” kind of situation.Hyperparameter optimizationThePoniardBaseEstimator.tune_estimatormethod can be used to optimize the hyperparameters of a given estimator,
either by passing a grid of parameters or using the inbuilt ones
available for default estimators. The tuned estimator will be added to
the list of estimators and will be scored the next timePoniardBaseEstimator.fitis called.PlottingTheplotaccessor provides several plotting methods based on the
attached Poniard estimator instance. These Plotly plots are based on a
default template, but can be modified by passing a differentPoniardPlotFactoryto the Poniardplot_optionsargument.Plugin systemThepluginsargument in Poniard estimators takes a plugin or list of
plugins that subclassBasePlugin.
These plugins have access to the Poniard estimator instance and hook
onto different sections of the process, for example, on setup start, on
fit end, on remove estimator, etc.This makes it easy for third parties to extend Poniard’s functionality.Two plugins are baked into Poniard. 1. Weights and Biases: logs your
data, plots, runs wandb scikit-learn analysis, saves model artifacts,
etc. 2. Pandas Profiling: generates an HTML report of the features and
target. If the Weights and Biases plugin is present, also logs this
report to the wandb run.The requirements for these plugins are not included in the base Poniard
dependencies, so you can safely ignore them if you don’t intend to use
them.Design philosophyNot another dependencyWe try very hard to avoid cluttering the environment with stuff you
won’t use outside of this library. Poniard’s dependencies are:scikit-learn (duh)pandasXGBoostPlotlytqdmThat’s it!Apart fromtqdmand possiblyPlotly, all dependencies most likely
were going to be installed anyway, so Poniard’s added footprint should
be small.We don’t do that here (AutoML)Poniard tries not to take control away from the user. As such, it is not
designed to perform 2 hours of feature engineering and selection, try
every model under the sun together with endless ensembles and select the
top performing model according to some metric.Instead, it strives to abstract away some of the boilerplate code needed
to fit and compare a number of models and allows the user to decide what
to do with the results.Poniard can be your first stab at a prediction problem, but it
definitely shouldn’t be your last one.Opinionated with a few exceptionsWhile some parameters can be modified to control how variable type
inference and preprocessing are performed, the API is designed to
prevent parameter proliferation.Cross validate all the thingsEverything in Poniard is run with cross validation by default, and in
fact no relevant functionality can be used without cross validation.Use baselinesA dummy estimator is always included in model comparisons so you can
gauge whether your model is better than a dumb strategy.Fast TTFM (time to first model)Preprocessing tries to ensure that your models run successfully without
significant data munging. By default, Poniard imputes missing data and
one-hot encodes or target encodes (depending on cardinality) inferred
categorical variables, which in most cases is enough for scikit-learn
algorithms to fit without complaints. Additionally, it scales numeric
data and drops features with a single unique value.Similar projectsPoniard is not a groundbreaking idea, and a number of libraries follow a
similar approach.ATOMis perhaps the most similar
library to Poniard, albeit with a different approach to the API.LazyPredictis
similar in that it runs multiple estimators and provides results for
various metrics. Unlike Poniard, by default it tries most scikit-learn
estimators, and is not based on cross validation.PyCaretis a whole other beast
that includes model explainability, deployment, plotting, NLP, anomaly
detection, etc., which leads to a list of dependencies several times
larger than Poniard’s, and a more complicated API.