-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathIris_demo_app.py
More file actions
65 lines (52 loc) · 2.24 KB
/
Iris_demo_app.py
File metadata and controls
65 lines (52 loc) · 2.24 KB
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
63
64
65
import streamlit as st
import pandas as pd
from sklearn import datasets
from sklearn.ensemble import RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn import metrics
from sklearn.naive_bayes import GaussianNB
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis, QuadraticDiscriminantAnalysis
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.linear_model import LogisticRegression
st.write("""
# Dehao's Iris Flower Prediction App
This app predicts the **Iris flower** type based on user input sepal/petal measurements!
""")
st.sidebar.header('User Input Parameters')
def user_input_features():
sepal_length = st.sidebar.slider('Sepal length', 4.3, 7.9, 5.4)
sepal_width = st.sidebar.slider('Sepal width', 2.0, 4.4, 3.4)
petal_length = st.sidebar.slider('Petal length', 1.0, 6.9, 1.3)
petal_width = st.sidebar.slider('Petal width', 0.1, 2.5, 0.7)
data = {'sepal_length': sepal_length,
'sepal_width': sepal_width,
'petal_length': petal_length,
'petal_width': petal_width}
features = pd.DataFrame(data, index=[0])
return features
df = user_input_features()
st.subheader('User Input parameters')
st.write(df)
iris = datasets.load_iris()
X = iris.data
Y = iris.target
st.subheader('Class labels and their corresponding index number')
st.write(iris.target_names.reshape(1,3))
models = []
pred = []
models.append(('Decision Tree', DecisionTreeClassifier(max_depth = 3, random_state = 1)))
models.append(('Gaussian Naive Bayes', GaussianNB()))
models.append(('LDA', LinearDiscriminantAnalysis()))
models.append(('QDA', QuadraticDiscriminantAnalysis()))
models.append(('KNN', KNeighborsClassifier(n_neighbors = 3)))
models.append(('Logistic Regression', LogisticRegression(solver = 'newton-cg')))
models.append(('Linear SVC', SVC(kernel='linear')))
for name, model in models:
pred.append(iris.target_names[model.fit(X,Y).predict(df)])
idx = [models[i][0] for i in range(len(models))]
pred = pd.DataFrame(pred, columns = ['Prediction'], index = idx)
st.subheader('Prediction for each classifier')
st.write(pred)
st.subheader('Prediction from the majority of classifiers')
st.write(pred['Prediction'].value_counts().index[0])