Enable exporting trained models to text files to be able to import later

### Describe the workflow you want to enable

```python
from sklearn.datasets import fetch_california_housing
from sklearn.ensemble import RandomForestRegressor

# make data
X,y = fetch_california_housing(return_X_y=True)

# instantiate Random-Forest and fit it
rf_model = RandomForestRegressor(min_samples_leaf=5, random_state=0, n_jobs=-1)
rf_model.fit(X, y)

# export model to a text file, inspired by https://xgboost.readthedocs.io/en/release_3.0.0/python/python_api.html#xgboost.XGBRegressor.save_model
rf_model.save_model("model.json")


#################### in a new python environment
from sklearn.ensemble import RandomForestRegressor
rf_model2 = RandomForestRegressor(min_samples_leaf=5, random_state=0, n_jobs=-1)
rf_model2.load_model("model.json")
```

### Describe your proposed solution

The current recommended way I believe is to export fit (or trained) models is to serialize them using joblib, which depends on python version, joblib version and scikit-learn version too, and I presume this may lead to issues with OS and CPU architecture as well (windows or  GNU Linux and x86 or ARM64).

So, I request a way to export model's trained weights (or other relevant things like bins & trees for RandomForestRegressor) for it be to loaded from any scikit-learn version or python version or operating system. This is just how the big packages like [xgboost](https://xgboost.readthedocs.io/en/release_3.0.0/python/python_api.html#xgboost.XGBRegressor.save_model) and pytorch ([using `state_dict`](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.load_state_dict)) and hence transformers,  handle things. 

This would enable to change environments and platforms easily without having to train model for the new package-versions, architecture and OS again or every time an update in them is required.

### Describe alternatives you've considered, if relevant

There is no alternative to everything that scikit-learn offers as of now.

### Additional context

This has been provied above.

COMMENT:
I think that using a text file to store a huge number of numerical parameters can be very inefficient and could introduce discrepancies via rounding errors of floating-point values converted to and from a decimal text representation.

You might instead want to take a look at `skops.io`:

https://skops.readthedocs.io/en/latest/persistence.html

Internally, `skops.io` uses a mixed json + binary arrays storage format.

However, loading a model trained and persisted with an older version of scikit-learn is not always guaranteed to work either (quoting a paragraph from the linked doc):

> Using skops to load a model saved in one sklearn version and loading it with another sklearn version is not recommended, because the behavior of the model may change across versions. In some cases loading the model in a different version might not be possible due to internal changes in scikit-learn. Such changes don’t happen very often, but they can happen, thus you should be cautious. To replicate a model trained with one sklearn version using a different sklearn version, it is advised to retrain the model on the same data using the same training process.

Maintaining a versioned serialization format that automatically handles scikit-learn migrations has been discussed in the past, and the general agreement was that it is out of the scope of the scikit-learn project for the sake of keeping maintenance costs under control.

It might be possible to build such a migration tool top of `skops.io` (or maybe even part of it) but as far as I know, nobody has the decided to invest the time and effort to do it. Doing it would involve setting up a complex continuous integration infrastructure to train and archive models with past scikit-learn versions and test that they can still be loaded and executed with newer versions. Whenever a problem is detected between 2 versions, a dedicated migration code should be implemented and included in the migration tool. Setting up such a testing infrastructure requires a non-trivial effort. If your company really needs this, it might be possible to set up a contract to develop and maintain such a tool:

https://scikit-learn.org/dev/support.html#paid-support

Otherwise, I would just make sure that your training pipeline is under version control and runs are automated using a some kind of continuous integration or MLops platform and that you lock a version of its dependencies using tools such as [pixi](https://pixi.sh/) or [uv compile](https://docs.astral.sh/uv/pip/compile/) such that it's easy to trigger a retrain job with a controlled version of the libraries when skops or pickle fail to load a model trained with old versions of the libraries.

cc @adrinjalali who is a maintainer of skops.

Labels: New Feature, Needs Decision - Include Feature