Skip to content

sklego/unseeded-random-estimator

Pack Severity Fix Versions
scikit-lego info unsafe, with xpd check --fix --unsafe-fixes All versions

RandomRegressor and RandomAdder without random_state draw new numbers on every call, so results change between calls. Pass random_state=.

baseline = RandomRegressor(strategy="normal")
baseline = RandomRegressor(strategy="normal", random_state=0)

The rule reports RandomRegressor and RandomAdder built without random_state, outside test files. Each call then draws new numbers.

With --unsafe-fixes, xpd supplies random_state=0. Choose a different seed if your project uses one.

Two predict calls of one fitted RandomRegressor() differed, and so did two transform calls of one RandomAdder() on its training rows. Both pairs were equal with random_state=0.

$C without random_state draws new numbers on every call, so two calls on one fitted object gave different results. Pass random_state= to make the run repeatable.

See all rules in the scikit-lego pack.