|
import numpy as np
|
|
import pickle
|
|
from sklearn.datasets import load_iris
|
|
from sklearn.model_selection import train_test_split
|
|
from sklearn.preprocessing import StandardScaler
|
|
from sklearn.ensemble import RandomForestClassifier
|
|
|
|
|
|
iris = load_iris()
|
|
X, y = iris.data, iris.target
|
|
|
|
|
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
|
|
|
|
|
scaler = StandardScaler()
|
|
X_train = scaler.fit_transform(X_train)
|
|
X_test = scaler.transform(X_test)
|
|
|
|
|
|
with open('scaler.pkl', 'wb') as f:
|
|
pickle.dump(scaler, f)
|
|
|
|
|
|
model = RandomForestClassifier(n_estimators=100, random_state=42)
|
|
model.fit(X_train, y_train)
|
|
|
|
|
|
with open('iris_classifier_model.pkl', 'wb') as f:
|
|
pickle.dump(model, f) |