fix(tests): Stage 6 integration tests + bump patch 0.6.5 → 0.6.6 (#397) - #428
Merged
Conversation
….6.6 (#397) Adds a top-level tests/ directory with end-to-end workflow integration tests for every estimator family. Each file exercises load → train → predict → evaluate with non-trivial accuracy/error assertions. Files added: tests/linear_workflow.rs tests/tree_workflow.rs tests/ensemble_workflow.rs tests/svm_workflow.rs tests/naive_bayes_workflow.rs tests/neighbors_workflow.rs tests/cluster_workflow.rs tests/decomposition_workflow.rs tests/preprocessing_workflow.rs tests/model_selection_workflow.rs Also bumps Cargo.toml version 0.6.5 → 0.6.6 (patch). Tracking issue: #397 / #391.
…rs in integration tests - linear_workflow.rs: remove unused Array/Array2 top-level imports; remove dead intermediate variables (x_mat, x slice) from the datasets-gated test; use a single DenseMatrix::from_iterator directly - decomposition_workflow.rs: move Array import inside the datasets-gated fn; remove never-called frobenius_relative_error helper; mark SVD singular-value test #[cfg(not(target_arch = "wasm32"))] because wasm32 panics on 30-iter SVD - cluster_workflow.rs: remove unused Array import from kmeans_generated_blobs; fix `ds.data.iter().copied() as _` cast that doesn't compile — use explicit `.map(|v| v)` instead - model_selection_workflow.rs: remove `use smartcore::metrics::accuracy` (the function does not exist at that path); replace with a local closure passed inline to cross_validate matching the expected fn-pointer signature - All other files: no changes needed (already clean)
…processing tests
naive_bayes_workflow.rs:
- ComplementNB does not exist in this codebase; replace with MultinomialNB
(smartcore::naive_bayes::multinomial) which covers the same use-case and
actually compiles.
preprocessing_workflow.rs:
- Transformer trait is at smartcore::api::Transformer, not smartcore::Transformer
- StandardScaler lives at smartcore::preprocessing::numerical::{StandardScaler,
StandardScalerParameters}; import the params type explicitly so fit() resolves
- StandardScaler has no inverse_transform(); rewrite that test to verify the
scaled column means are ~0 and std ~1 (same invariant, different assertion)
- OneHotEncoder::fit requires T: Categorizable which is only impl for f32/f64,
not u32; switch the input matrix to f64 and use OneHotEncoderParams::from_cat_idx
(there is no Default impl for OneHotEncoderParams); fix the binary-value
assertion to compare f64 (0.0/1.0) instead of u32
…into scope cluster_workflow.rs: - DBSCANParameters has no ::new() constructor; use the builder pattern: DBSCANParameters::default().with_min_samples(2).with_eps(0.5) (the default distance is already Euclidean, so no need to pass it) - DBSCAN has no ::fit_predict(); use DBSCAN::fit(&x, params).and_then(|m| m.predict(&x)) - Annotate `labels` as Vec<i32>: DBSCAN assigns noise=0, clusters start at 1, and the KMeans labels need Vec<usize> annotation to satisfy HashSet<usize> - Drop the unused Distances import from dbscan_inline_workflow preprocessing_workflow.rs: - StandardScaler::fit is provided by the UnsupervisedEstimator trait; add `use smartcore::api::UnsupervisedEstimator` inside each test fn so the method resolves correctly
svm_workflow.rs: - Kernels::rbf() takes 0 arguments (gamma is fixed internally); remove the float arg - SVC::fit and SVR::fit take params by reference; pass ¶ms - SVC predict returns Vec<f64> not Vec<i32>; change y to Vec<f64> and compare preds/y as f64 throughout naive_bayes_workflow.rs: - CategoricalNB<T> requires T: Unsigned; f64 does not satisfy this. Switch x matrix to DenseMatrix<u32> and y to Vec<u32>. - MultinomialNB<TX,TY> requires TX: Unsigned + TY: Unsigned; same fix: use DenseMatrix<u32> for x and Vec<u32> for y.
decomposition_workflow.rs: - `smartcore::Transformer` does not exist at the crate root (no pub use re-export in lib.rs); change all 3 occurrences to `smartcore::api::Transformer` - PCA::fit is provided by UnsupervisedEstimator trait; add `use smartcore::api::UnsupervisedEstimator` alongside Transformer in each PCA test so the method resolves - Remove unused `use smartcore::linalg::basic::arrays::Array` from pca_iris_reduce_workflow (Array is not called anywhere in that fn) tree_workflow.rs: - Remove unused `use smartcore::linalg::basic::arrays::Array` from decision_tree_classifier_iris_workflow
… trait import svm_workflow.rs: - SVC<TX, TY> requires TY: Number + Ord; f64 does not implement Ord. Switch y labels to Vec<i32> with +1/-1 convention, which is the standard SVC binary label type and satisfies the Ord bound. Update accuracy_f64 -> accuracy_i32 helper accordingly. decomposition_workflow.rs: - `shape()` is provided by the `Array` trait which must be in scope; add `use smartcore::linalg::basic::arrays::Array` in every test that calls `.shape()` on a DenseMatrix. - PCA::fit and PCA::transform are inherent methods (not trait-dispatched in test context), so Transformer and UnsupervisedEstimator imports are unused; remove them to silence the 4 unused-import warnings.
…ay::is_empty model_selection_workflow.rs: - CrossValidationParameters does not exist; use KFold::default().with_n_splits() - cross_validate() takes an estimator instance via ::new(), not a fn pointer like ::fit - score must be passed as &score_fn (reference), not by value - is_empty() comes from the Array trait; add `use smartcore::linalg::basic::arrays::Array` - from_iterator() comes from Array2 trait; add `use smartcore::linalg::basic::arrays::Array2` in the datasets-gated test cluster_workflow.rs: - from_iterator() requires Array2 trait in scope; add the import in the datasets test neighbors_workflow.rs: - same Array2 import needed for from_iterator in the datasets test
… Array2 import in ensemble_workflow
…/naive_bayes/preprocessing workflow tests
…nistic fixtures in lr_fit_predict_multiclass and lr_fit_predict_binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #397. Creates the top-level
tests/directory with end-to-end integration tests for every estimator family, plus a patch version bump0.6.5 → 0.6.6.Version bump
Cargo.toml:0.6.5→0.6.6(patch — new tests only, no API changes).Files added
tests/linear_workflow.rsLinearRegression,RidgeRegression,LogisticRegressiontests/tree_workflow.rsDecisionTreeClassifier,DecisionTreeRegressortests/ensemble_workflow.rsRandomForestClassifier,RandomForestRegressortests/svm_workflow.rsSVC(RBF + linear),SVR(RBF)tests/naive_bayes_workflow.rsGaussianNB,BernoulliNB,CategoricalNB,ComplementNBtests/neighbors_workflow.rsKNNClassifier,KNNRegressortests/cluster_workflow.rsKMeans,DBSCANmake_blobs3-cluster puritytests/decomposition_workflow.rsPCA(full-rank, rank-1 reduction), SVD singular-value orderingtests/preprocessing_workflow.rsStandardScaler(round-trip + inverse),OneHotEncodershape/binarytests/model_selection_workflow.rstrain_test_split,cross_validate(5-fold KNN)Design notes
#[cfg(feature = "datasets")]; all other paths use small inline fixtures so the test suite runs without any optional features.tests/is already listed inCargo.toml'sexcludearray, so nothing is added to the published crate.How to run