-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
168 lines (128 loc) · 6.24 KB
/
index.html
File metadata and controls
168 lines (128 loc) · 6.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- numpy
- matplotlib
- scikit-learn
- pandas
- panel==0.13.1a2
- paths:
- ./test_module.py
</py-env>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
<div type="fileinput"></div>
<py-title> 기본사용방법 결과 </py-title>
<div id="plot"></div>
<py-script output="plot">
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from test_module import check
from sklearn.linear_model import LinearRegression
print(check(1,100))
x = np.random.randn(1000)
y = np.random.randn(1000)
fig, ax = plt.subplots()
ax.scatter(x, y)
fig
</py-script>
<py-title> pyscript&ML 비만도 알아보기 </py-title>
<div id="gridy"></div>
<div>이곳에 키와 몸무게를 입력해주세요(저장되지 않습니다)</div>
<div id="height-output"></div>
<py-script output="gridy">
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import LabelEncoder, StandardScaler
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split, cross_val_score
import pandas as pd
from js import console
def info_to_df(height, weight, gender):
height, weight = height / 100, weight / 100
check = pd.DataFrame(columns=["Height", "Weight", "gender"])
data_to_insert = {"Height": height, "Weight": weight, "gender": gender}
infodf = check.append(data_to_insert, ignore_index=True)
return infodf
def make_ml_answer(*args,**kwargs):
data = pd.DataFrame([['Male',174,96,4],
['Male',189,87,2],
['Female',185,110,4],
['Male',149,61,3],
['Male',189,104,3],
['Male',147,92,5],
['Male',154,111,5],
['Male',174,90,3],
['Female',169,103,4],
['Male',195,81,2],
['Female',159,80,4],
['Female',192,101,3],
['Male',155,51,2],
['Male',191,79,2],
['Female',153,107,5],
['Female',157,110,5],
['Male',140,129,5],
['Male',144,145,5],
['Male',172,139,5],
['Male',157,110,5],
['Female',153,149,5],
['Female',169,97,4],
['Female',195,104,3],
['Male',149,61,3]], columns = ['Gender','Height','Weight','Index'])
df = data
le = LabelEncoder()
df["gender"] = le.fit_transform(df["Gender"])
df["Height"] = df["Height"] / 100
df["Weight"] = df["Weight"] / 100
X = df.drop(["Index", "Gender"], axis="columns")
y = df["Index"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.15)
model = KNeighborsClassifier(n_neighbors=5)
test = model.fit(X_train, y_train)
string_height = document.getElementById('height').value;
string_weight = document.getElementById('weight').value;
string_gender = document.getElementById('gender').value;
check_height = int(round(float(string_height)))
check_weight = int(round(float(string_weight)))
check_gender = int(round(float(string_gender)))
console.log(check_height);
console.log(check_weight);
console.log(check_gender);
console.log("test",int(check_height));
height,weight,gender = int(check_height),int(check_weight), int(check_gender)
print("키몸무게성별 잘나오나??",height,weight,gender)
print("키몸무게성별 잘나오나??",type(height),type(weight),gender)
if height:
print("키 나옴??")
prediction = test.predict(info_to_df(height, weight, gender))
print("prediction",prediction)
prediction_dict = {1: "깡마름", 2: "마름", 3: "보통", 4: "통통", 5: "뚱뚱"}
prediction_name = prediction_dict[prediction[0]]
print("결과값:",prediction_name)
pyscript.write("result",prediction_name)
</py-script>
<div class="input-group mb-3">
<span class="input-group-text">키</span>
<input id="height" type="text" class="form-control" aria-label="Amount (to the nearest dollar)"/>
<span class="input-group-text">cm</span>
<span class="input-group-text">몸무게</span>
<input id="weight" type="text" class="form-control" aria-label="Amount (to the nearest dollar)"/>
<span class="input-group-text">kg</span>
<span class="input-group-text">성별</span>
<input id="gender" type="text" class="form-control" aria-label="Amount (to the nearest dollar)"/>
<span class="input-group-text">남자:1 / 여자:2</span>
</div>
<button id="make_ml_answer" type="submit" pys-onClick="make_ml_answer" class="btn btn-primary">누르기</button>
<div class="form-floating">
<textarea class="form-control" placeholder="Leave a comment here" id="result"></textarea>
<label for="result">이곳에서 결과가 나옵니다(깡마름/마름/보통/통통/뚱뚱)</label>
</div>
</body>
</html>