-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdatacraft.py
134 lines (115 loc) · 3.12 KB
/
datacraft.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import numpy as np
import streamlit as st
from utils.functions import (
add_polynomial_features,
generate_data,
get_model_tips,
get_model_url,
plot_decision_boundary_and_metrics,
train_model,
)
from utils.ui import (
dataset_selector,
footer,
generate_snippet,
polynomial_degree_selector,
introduction,
model_selector,
)
st.set_page_config(
page_title="Docker Workshop", layout="wide", page_icon="./images/flask.png"
)
st.image(["./images/ekidatacraft.png"],width=300)
def sidebar_controllers():
dataset, n_samples, train_noise, test_noise, n_classes = dataset_selector()
model_type, model = model_selector()
x_train, y_train, x_test, y_test = generate_data(
dataset, n_samples, train_noise, test_noise, n_classes
)
st.sidebar.header("Feature engineering")
degree = polynomial_degree_selector()
footer()
return (
dataset,
n_classes,
model_type,
model,
x_train,
y_train,
x_test,
y_test,
degree,
train_noise,
test_noise,
n_samples,
)
def body(
x_train, x_test, y_train, y_test, degree, model, model_type, train_noise, test_noise
):
introduction()
col1, col2 = st.beta_columns((1, 1))
with col1:
plot_placeholder = st.empty()
with col2:
duration_placeholder = st.empty()
model_url_placeholder = st.empty()
code_header_placeholder = st.empty()
snippet_placeholder = st.empty()
tips_header_placeholder = st.empty()
tips_placeholder = st.empty()
x_train, x_test = add_polynomial_features(x_train, x_test, degree)
model_url = get_model_url(model_type)
(
model,
train_accuracy,
train_f1,
test_accuracy,
test_f1,
duration,
) = train_model(model, x_train, y_train, x_test, y_test)
metrics = {
"train_accuracy": train_accuracy,
"train_f1": train_f1,
"test_accuracy": test_accuracy,
"test_f1": test_f1,
}
snippet = generate_snippet(
model, model_type, n_samples, train_noise, test_noise, dataset, degree
)
model_tips = get_model_tips(model_type)
fig = plot_decision_boundary_and_metrics(
model, x_train, y_train, x_test, y_test, metrics
)
plot_placeholder.plotly_chart(fig, True)
duration_placeholder.warning(f"Training took {duration:.3f} seconds")
model_url_placeholder.markdown(model_url)
code_header_placeholder.header("**Retrain the same model in Python**")
snippet_placeholder.code(snippet)
tips_header_placeholder.header(f"**Tips on the {model_type} 💡 **")
tips_placeholder.info(model_tips)
if __name__ == "__main__":
(
dataset,
n_classes,
model_type,
model,
x_train,
y_train,
x_test,
y_test,
degree,
train_noise,
test_noise,
n_samples,
) = sidebar_controllers()
body(
x_train,
x_test,
y_train,
y_test,
degree,
model,
model_type,
train_noise,
test_noise,
)