rheon.gram.lars_paths¶
- rheon.gram.lars_paths(grams: Sequence[Gram], *, targets: Sequence[str | int] | None = None, features: Sequence[str | int] | None = None, max_iter: int | None = None, max_active: int | None = None, penalty_weights: Sequence[float] | None = None, threads: int | None = None) list[list[dict[str, Any]]][source]¶
Compute
lars_path()for many Grams and targets at once, on the process’s threads.Use it to walk the lasso path of every group’s Gram, or of every target, in one call. To pool subsets of the Grams first and walk each pooled Gram’s path, use
solve_subsets(). For one path,lars_path()is the same arithmetic.Parameters
gramsThe Grams, each as
gram()returns it, all with the samecolumns. Each is fitted as it is: nothing is merged, and a Gram pooled within parts has its interceptnan.targetsThe targets to walk, by name or position, in each Gram. Default
None, every target of each Gram.features,max_iter,max_active,penalty_weightsAs for
lars_path(), applied to every path,max_iter’s older namemax_stepsrefused, as forlars_path().threadsHow many threads the Grams run on, beside each other:
None, the default, is the process’s threads, whichRHEON_MAX_THREADSsizes, and an integer that many threads, asModelBanktakes it. Refused unless an integer of at least 1, orNone.
Returns
One list per Gram, with one path per target, each the dict
lars_path()returns. An emptygramsgives an empty list.Raises
ValueErrorGrams of different
columns, as formerge().
Otherwise, it raises what
lars_path()raises.Examples
This code reads
dffrom Example data:spec = rp.spec.ewridge("ridge", targets=["y"], features=["x0", "x1"], half_life=100.0, group="stock_id") bank = rp.ModelBank([spec]) bank.fit_predict(df) paths = rp.gram.lars_paths(bank.gram("ridge"), max_active=1) # one list per stock # the first column to enter each stock's path print([per_gram[0]["active"][-1] for per_gram in paths])
[['x0'], ['x0'], ['x0'], ['x0']]
See also
lars_path(), one path.solve_subsets(), whosejobsgive each path columns of its own, on pooled subsets of the Grams.
Notes
Each Gram’s column scaling is formed once, and its targets’ paths run beside each other on it, each reading only its active columns’ rows of the correlation matrix from the co-moments. A path is the same arithmetic on one thread whatever the number of threads, so its numbers are those of
lars_path()to the bit.solve_subsets()withpathand one Gram a subset,[[0], [1], ...], gives each subset the pathlars_path()gives on that Gram, to the bit.