-
Notifications
You must be signed in to change notification settings - Fork 0
/
flask-predict-train.py
62 lines (29 loc) · 1008 Bytes
/
flask-predict-train.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 16 20:54:46 2018
@author: vivekkalyanarangan
"""
# Random Forest Classifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import pandas as pd
# loading the dataset
iris = load_iris()
X = iris.data
y = iris.target
# Split the data
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42, test_size=0.5)
# Build the model
clf = RandomForestClassifier(n_estimators=10)
# Train the classifier
clf.fit(X_train, y_train)
# Predictions
predicted = clf.predict(X_test)
# Check accuracy
print(accuracy_score(predicted, y_test))
import pickle
with open('/Users/vivekkalyanarangan/Desktop/rf.pkl', 'wb') as model_pkl:
pickle.dump(clf, model_pkl, protocol=2)