Spaces:
Running
Running
File size: 819 Bytes
17e1815 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
import pickle
# Load the csv file
df = pd.read_csv("iris.csv")
print(df.head())
# Select independent and dependent variable
X = df[["Sepal_Length", "Sepal_Width", "Petal_Length", "Petal_Width"]]
y = df["Class"]
# Split the dataset into train and test
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=50)
# Feature scaling
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test= sc.transform(X_test)
# Instantiate the model
classifier = RandomForestClassifier()
# Fit the model
classifier.fit(X_train, y_train)
# Make pickle file of our model
pickle.dump(classifier, open("model.pkl", "wb")) |