Footspace / create_model.py
Oumar450's picture
first commit
3b52e32
Raw History Blame Contribute Delete
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()