-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
33 lines (25 loc) · 903 Bytes
/
model.py
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
32
33
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
# K Nearest Neighbors
from sklearn.neighbors import KNeighborsClassifier
classifier_KNN = KNeighborsClassifier()
# Fit the model
classifier_KNN.fit(X_train, y_train)
# Make pickle file of our model
pickle.dump(classifier_KNN, open("model.pkl", "wb"))