Download scikit-learn/gaussian_nb/train.py from activeeon/models-repository: direct link, hf CLI and curl.
- Browser
- Download file 646 Bytes
-
https://huggingface.co/activeeon/models-repository/resolve/main/scikit-learn/gaussian_nb/train.py
- Command line
-
hf download hf://activeeon/models-repository/scikit-learn/gaussian_nb/train.py
-
curl -L -o train.py https://huggingface.co/activeeon/models-repository/resolve/main/scikit-learn/gaussian_nb/train.py
646 Bytes
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| import joblib | |
| import numpy as np | |
| from sklearn.datasets import load_iris | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.naive_bayes import GaussianNB | |
| # Set the random seed | |
| random_seed = 0 | |
| np.random.seed(random_seed) | |
| # Load the dataset | |
| dataset = load_iris() | |
| X, y = dataset.data, dataset.target | |
| # Split the dataset into training and testing sets | |
| X_train, _, y_train, _ = train_test_split(X, y, test_size=0.25, random_state=random_seed) | |
| # Create and train model | |
| model = GaussianNB() | |
| model.fit(X_train, y_train) | |
| # Save the model to disk | |
| joblib.dump(model, 'gaussian_nb.joblib') | |