Download create_model.py from Oumars78/Footspace: direct link, hf CLI and curl.
- Browser
- Download file 814 Bytes
-
https://huggingface.co/spaces/Oumars78/Footspace/resolve/main/create_model.py
- Command line
-
hf download hf://spaces/Oumars78/Footspace/create_model.py
-
curl -L -o create_model.py https://huggingface.co/spaces/Oumars78/Footspace/resolve/main/create_model.py
814 Bytes
| import pickle | |
| from sklearn.datasets import load_iris | |
| from sklearn.ensemble import RandomForestClassifier | |
| from sklearn.pipeline import Pipeline | |
| from sklearn.preprocessing import StandardScaler | |
| from sklearn.model_selection import train_test_split | |
| def build_and_save_model(output_path="model.pkl"): | |
| data = load_iris() | |
| X, y = data.data, data.target | |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) | |
| pipe = Pipeline([ | |
| ("scaler", StandardScaler()), | |
| ("clf", RandomForestClassifier(n_estimators=50, random_state=42)) | |
| ]) | |
| pipe.fit(X_train, y_train) | |
| with open(output_path, "wb") as f: | |
| pickle.dump(pipe, f) | |
| print(f"Model entraîné et sauvegardé dans {output_path}") | |
| if __name__ == "__main__": | |
| build_and_save_model() | |