Repository navigation
Add plot= to the remaining functions; R's column names and bool factors - #163
Closed
gitRasheed wants to merge 11 commits into
Closed
gitRasheed wants to merge 11 commits into
gitRasheed wants to merge 11 commits into
Conversation
gitRasheed
force-pushed
the
rasheed/api-polish
branch
from
November 2, 2026 04:11
cd65c5a to
b0c9f32
Compare
gitRasheed
force-pushed
the
rasheed/parity-cache-tests
branch
from
November 2, 2026 04:12
c4b47bf to
65f2970
Compare
plot=True worked on nns_reg (univariate), nns_cdf, nns_seas, nns_arma and nns_arma_optim, but nns_part, fsd, ssd, tsd, nns_anova, nns_norm, nns_diff and nns_copula raised TypeError for it although R has the argument and nns.plotting already had a plotter for each. Multivariate nns_reg(plot=True, residual_plot=True) and nns_sd_cluster(dendrogram=True) silently drew nothing. - Add keyword plot: bool = False to those eight functions, delegating to plot_nns_part / plot_fsd / plot_ssd / plot_tsd / plot_nns_anova / plot_nns_norm (raw and normalized panels, R's chart.type = "l") / plot_nns_diff / plot_nns_copula. Return values are unchanged. - Multivariate nns_reg: residual_plot=True draws the NNS.M.reg fitted-values plot, plot=True a 3-D scatter for two regressors (as R's rgl branch) and a UserWarning for more. - nns_sd_cluster(dendrogram=True) draws the dendrogram with scipy, as R does, and warns like R when fewer than two variables are clustered. - nns_copula with more than three variables and nns_norm on unequal-length lists warn instead of drawing nothing. The default stays False (no side effects), a documented divergence from R's plot = TRUE defaults (docs/conventions.md, new Plotting section). Numerical results do not change.
- _rrng.RRNG.sample_int_prob_noreplace had no callers and did not reproduce R's ProbSampleNoReplace (R revsorts the probabilities first: set.seed(42); sample.int(5, 3, prob = c(.1, .5, .2, .15, .05)) gives 1 4 2 in R and 4 3 2 here). Removed rather than fixed, since nothing needs weighted sampling without replacement. - categorical._down_sample_rows, _up_sample_rows, _balance_class_training and their _sampling_inputs helper were used only by their own test (tests/invariants/test_sampling.py, removed). They drew from the NumPy RNG in a layout that nns_stack and nns_boost no longer use. - boost.py duplicated stack.py's _scalar_logical and _scalar_integer verbatim; boost now imports them from nns.stack. No public behaviour changes.
- An obj_fn returning a vector failed deep inside with "TypeError: only 0-dimensional arrays can be converted to Python scalars". nns_stack and nns_boost now raise R's "[obj.fn] must return one numeric value." for any result that is not a single number (a length-1 array is accepted, as R accepts a length-1 vector). - random_seed= (alias of seed=) replaced seed only while seed was 123: seed=7, random_seed=5 silently used 7 and seed=None, random_seed=5 drew OS entropy. The alias now always applies, and two different explicit values raise ValueError (seed=123 is the default and cannot be told apart from an explicit 123). - nns_boost(feature_importance=True) was silently ignored. R draws its learner/feature-frequency diagnostics there; the port draws nothing, so it now warns and points at result['feature.frequency']. Results for valid inputs do not change. Skipped: status printing style, the documented two-valued auto-classification, and the seed=None stream structure (behaviour, not a bug). ncores is honoured (caps native threads), so it is not a no-op.
- R's .nns_reg_as_frame builds the predictor frame with
check.names = FALSE and only applies make.unique, so a column "my col"
stays "my col" and "2nd" stays "2nd" in RPM / Fitted.xy. The port ran the
names through make.names ("my.col", "X2nd"). Names are now only
de-duplicated. Factor dummy names are unchanged (R make.names the levels:
"my cyl_four").
- Numeric class levels were str(float): ['0.0', '1.0'] where R's
as.character gives c("0", "1") (and "0.333333333333333" for 1/3). They
now use 15 significant digits.
- The zero-variance branch of the Racine-Hastie R2 used exact equality
where R uses isTRUE(all.equal(actual, predicted)); a constant fit off by
1e-12 scored 0 instead of R's 1. Both _r2 helpers now use an all.equal
port (R: f(rep(3,5), rep(3+1e-12,5)) = 1, f(rep(3,5), rep(3+1e-7,5)) = 0).
New parity tests record R from the patched NNS 13.3. Values do not change;
only result key names for non-syntactic column labels and the
class.levels strings of numeric responses do. Skipped: the
R-only location= plotting argument, and items already fixed (ncores
warning, the levels.index loop).
R's .nns_reg_encode_predictors makes a factor of every is.factor || is.character || is.logical column. The port kept bool columns numeric 0/1, so a univariate bool x stayed on the univariate path (Point.est 47.3 / 48.2) where R builds the dummies x_FALSE. / x_TRUE. and runs NNS.M.reg (48.75 / 48.75; audit api1 case). bool columns, and object columns whose values are all booleans, are now factors with levels FALSE/TRUE. Dummy names go through the R make.names port that appends "." to reserved words (x_FALSE., x_TRUE.), which the local make.names copy lacked; that copy is removed. New parity tests (univariate bool vector, and a bool + numeric frame with factor.2.dummy TRUE and FALSE) match R for Point.est, R2 and the RPM names. The other predictor-typing case (numeric-looking strings) already follows R: string columns are factors. Results change only for bool predictors.
… kernel The pure-Python _fast_lm used np.mean/np.sum (pairwise), while NNS-core's fast_lm (R's Rcpp kernel) uses long-double two-pass means and sequential sums. The intercept then differed in the last bit, tied residuals sorted differently, and nns_meboot/nns_arma/nns_mc gave different replicates with NNS_DISABLE_NATIVE=1 for the same seed (e.g. meboot ordxx [3,1,2] vs R's [1,3,2]). Found by the independent review of the branch.
Before ncores was honoured it was ignored, and R's univariate paths accept any value, so ncores=0 or scikit-style -1 now raised where they used to work. Map them to the default thread count with a DeprecationWarning; other invalid values (1.5, True, '2') still raise. Also pin the _fast_lm fallback to the native kernel in a test.
It kept bool columns numeric, so direct and prepared regressions on a bool x gave 48.75/48.75 vs 47.38/48.38; both now give R's 48.75 with x_FALSE./x_TRUE.
The display grid reaches x <= 0, so nns_diff(math.log, 5, plot=True) raised "math domain error"; it now returns the derivative 0.200000000258 and plots.
external_stacklevel stopped at contextlib's __enter__, so the warning named contextlib.py:141; it now names the caller's file and line.
They point at notes that don't live in this repo.
gitRasheed
force-pushed
the
rasheed/api-polish
branch
from
November 2, 2026 23:09
b0c9f32 to
f93a098
Compare
Contributor
|
Incorporated through NNS R 14.0 integration #192, merged as |
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.
The remaining API rough edges from the audit.
plot=Trueraised TypeError on eight compute functions that R andnns.plottingboth support.nns_stackandnns_boosthad confusing seed-alias andobj_fnerrors.nns_regrenamed non-syntactic columns and kept bool predictors numeric where R makes them factors. Dead sampling helpers remained.Stacked on #162; merge with a merge commit.
Changes
nns_part,fsd,ssd,tsd,nns_anova,nns_norm,nns_diffandnns_copulatakeplot: bool = Falseand draw with the existing plotters. Multivariatenns_reg(residual_plot=True)andnns_sd_cluster(dendrogram=True), which drew nothing, now draw, and undrawable cases warn. The default stays False, a documented divergence from R'splot = TRUE.obj_fnthat returns more than one number raises R's "[obj.fn] must return one numeric value."random_seed=always applies, and two different explicit seeds raise.nns_boost(feature_importance=True)warns that the port draws nothing.nns_regkeeps raw column names such as "my col" and only de-duplicates them, as R'scheck.names = FALSEdoes. Numeric class levels print as R'sas.characterdoes ("0", not "0.0"). The zero-variance R2 uses anall.equalport, so a constant fit off by 1e-12 scores 1, as in R.NNS.M.regwith dummies, as in R: Point.est goes from 47.3 / 48.2 to 48.75 / 48.75.prepare_factor_predictorsnow builds its design withnns_reg's own encoder, so the two always agree. Its dummy names follownns_reg:V1_*for an unnamed matrix andx_*for a vector (they wereX1_*), DataFrame column names are kept, and string columns withoutfactor_levelsbecome factors._fast_lmfallback uses R's long-double means and sequential sums, like the native kernel. Before,nns_mebootwithNNS_DISABLE_NATIVE=1sorted tied residuals differently and gave different replicates for the same seed.ncoresbelow 1 (0, or scikit-style -1) maps to the default thread count with a DeprecationWarning instead of raising. These values worked beforencoreswas honoured.sample_int_prob_noreplace, which did not reproduce R'sProbSampleNoReplaceand had no callers, the unused NumPy balancing helpers and their test, and boost's copies of two stack validators.Numerical results for valid inputs do not change, except for bool predictors.
Tests
New
tests/plotting/test_plot_flags.py, parity tests for raw names, numeric class levels and bool predictors, and invariants for the stack/boost errors, the R2 tie rule, the_fast_lmfallback against native, andncoresbelow 1. The parity cache encodes R 13.3 with the audit's R patches.See #147
Update
This push fixes
prepare_factor_predictors(names=...). Prediction columns used to be matched by the output prefixes, sonames=['b', 'a']swapped the values ([[25, 2.5]]), and a prefix that wasn't a training column raised ValueError. Columns now match the training columns by name, andnamesonly sets the prefixes.Review
GPT-6.1 Sol reviewed this slice and raised three findings. We took all three.
nns_regandprepare_factor_predictors(48.75 against 47.38; R gives 48.75).prepare_factor_predictorsnow usesnns_reg's encoder, and both give R's 48.75.nns_diff(math.log, 5, plot=True)failed in the display grid with a math domain error. Undefined display points are drawn as gaps, and the call returns 0.200000000258.ncores=0DeprecationWarning pointed at contextlib instead of the caller. It now names the caller, and the test asserts the filename.Sharing the encoder goes slightly beyond what the review asked for:
prepare_factor_predictorsnow names dummiesV1_*/x_*instead ofX1_*, keeps DataFrame column names and turns string columns into factors. The fix commits have not been re-reviewed.