-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoha.py
More file actions
301 lines (199 loc) · 13.8 KB
/
joha.py
File metadata and controls
301 lines (199 loc) · 13.8 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import streamlit as st
import pandas as pd
import plotly.graph_objects as go
data = {
'年': [1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022],
'臺灣地區': [1070268, 1089575, 1091478, 1064136, 1064153, 1064825, 1074665, 1082168, 1099739, 1108674, 1099994, 1074180, 1071938, 1104265, 1122379, 1140271, 1157926, 1167284, 1194572, 1231112, 1249031, 1274196, 1293719, 1314023, 1340848],
'新北市': [1087242, 1102563, 1095192, 1098408, 1100003, 1093053, 1109639, 1135398, 1125605, 1099472, 1159279, 1110774, 1071131, 1116342, 1101389, 1129598, 1146991, 1171978, 1223867, 1265798, 1292753, 1319841, 1352548, 1381603, 1421385],
'臺北市': [1442675, 1472979, 1530735, 1505506, 1514440, 1501916, 1488180, 1514069, 1526228, 1550134, 1538257, 1515793, 1564298, 1537890, 1570778, 1545415, 1575819, 1581899, 1568945, 1648122, 1649348, 1723021, 1716591, 1732126, 1752411],
'桃園市': [1163181, 1174654, 1209363, 1143050, 1192731, 1163092, 1203215, 1192419, 1179444, 1210511, 1182721, 1146080, 1122238, 1183732, 1238698, 1257146, 1327963, 1307158, 1317790, 1337361, 1378732, 1392199, 1424027, 1448909, 1449549],
'臺中市': [1102701, 1137007, 1038480, 1055944, 1015972, 1023452, 990633, 988496, 1048174, 1105239, 1026631, 977731, 987259, 1100346, 1067060, 1126875, 1152523, 1169183, 1140325, 1245350, 1279865, 1298497, 1289700, 1304508, 1338826],
'臺南市': [911488, 896601, 933736, 872189, 898270, 936057, 943051, 881412, 950332, 972699, 976116, 924950, 886924, 948383, 927231, 996434, 991990, 1007093, 1063495, 1079199, 1086077, 1079174, 1086475, 1120580, 1143699],
'高雄市': [1029317, 1051762, 1031569, 1003108, 974592, 972280, 1011408, 1046729, 1030212, 1081799, 1068765, 1052162, 1052260, 1043941, 1085971, 1107383, 1112287, 1145895, 1166824, 1186204, 1219246, 1224668, 1224100, 1231562, 1263068],
'宜蘭縣': [976550, 1022506, 972996, 877199, 846963, 943028, 874576, 994967, 931588, 909097, 1006018, 904809, 971775, 877016, 1075706, 979013, 1071335, 1160320, 1085846, 1098807, 1069997, 1093475, 1138365, 1136419, 1165558],
'新竹縣': [1113042, 1167454, 1232173, 1106603, 1127123, 1133617, 1196515, 1304360, 1164274, 1098234, 1289463, 1281933, 1300116, 1372358, 1367712, 1346768, 1389453, 1283995, 1365150, 1616327, 1519478, 1539555, 1619782, 1689337, 1702134],
'苗栗縣': [943047, 945975, 935836, 944066, 921405, 949888, 895950, 931906, 1030851, 1000447, 919930, 926267, 964594, 1014144, 1012306, 1020185, 1100084, 1008241, 1166196, 1029485, 1045881, 1073028, 1161999, 1214424, 1273250],
'彰化縣': [951047, 891310, 897000, 845708, 943182, 962720, 945506, 906328, 961572, 922001, 902838, 890929, 887707, 920937, 953701, 936595, 940572, 926717, 994353, 970491, 997162, 1026792, 996066, 1086809, 1108221],
'南投縣': [875980, 1005079, 874344, 836262, 830936, 819394, 879780, 897891, 964953, 860836, 851992, 978331, 932725, 881743, 986881, 896557, 919551, 878760, 916199, 894368, 967369, 940893, 997605, 985686, 1048879],
'雲林縣': [782106, 889682, 810634, 873803, 817942, 809617, 849594, 769997, 906358, 794205, 767431, 744181, 748256, 817778, 824211, 838094, 865131, 876670, 896101, 868663, 860237, 933883, 988062, 1024191, 1016913],
'嘉義縣': [707349, 766905, 857615, 783819, 730084, 738385, 778574, 797895, 810323, 750236, 764933, 741766, 775017, 804668, 880625, 858253, 789406, 890742, 896217, 901022, 940780, 850597, 906554, 916631, 891498],
'屏東縣': [919710, 879362, 913848, 838027, 927042, 919906, 847872, 894772, 899657, 953471, 842372, 877498, 850116, 866795, 889560, 861063, 832681, 869818, 911258, 958999, 985681, 964547, 1064508, 1046302, 1083933],
'臺東縣': [702299, 725065, 780967, 760989, 774329, 737947, 755711, 695369, 753191, 860701, 699334, 805395, 674899, 733168, 796622, 799026, 820549, 746981, 797395, 889108, 884510, 874386, 891340, 911136, 916928],
'花蓮縣': [887914, 883537, 933625, 933484, 845923, 880361, 858345, 795376, 862688, 878356, 843646, 808632, 904472, 920602, 927400, 966607, 860613, 924706, 948501, 910090, 937898, 956973, 1032499, 1026488, 1010041],
'澎湖縣': [634053, 723916, 831230, 732306, 760406, 739670, 874714, 778659, 853872, 789752, 902952, 851835, 986954, 828441, 887077, 922916, 932694, 792696, 1069545, 857821, 959761, 1037554, 1091011, 796484, 919357],
'基隆市': [999088, 1058154, 1052113, 964170, 893884, 881716, 1048399, 1052699, 948817, 999562, 976639, 1026166, 1040931, 1018118, 955197, 1002341, 957360, 1072433, 1074314, 1096361, 1070748, 1140481, 1106963, 1111556, 1099526],
'新竹市': [1207558, 1268541, 1395702, 1419946, 1320717, 1344434, 1479816, 1361016, 1478303, 1554456, 1462204, 1426854, 1448209, 1479675, 1439066, 1535411, 1576797, 1427572, 1537317, 1572296, 1426379, 1602826, 1618903, 1602415, 1722889],
'嘉義市': [1059622, 958462, 1005451, 975877, 1015957, 927635, 832402, 984171, 966863, 899387, 898229, 836551, 842337, 925444, 1095203, 1241161, 1157962, 1106004, 1154411, 1090947, 1152499, 1208298, 1225219, 1217617, 1282798]
}
df = pd.DataFrame(data) #各地區年收資料
st.sidebar.subheader('收入-選擇地區')
selected_areas = st.sidebar.multiselect(
'選擇地區',
options=df.columns[1:], # 不包含 '年' 欄位
default=['臺灣地區', '新北市', '臺北市', '桃園市', '臺中市', '臺南市', '高雄市'] # 預設選擇
)
st.write('# 臺灣地區收入變化')
# 使用 plotly 建立折線圖
fig = go.Figure()
# 添加每個選取的地區到圖表中
for area in selected_areas:
fig.add_trace(go.Scatter(x=df['年'], y=df[area], mode='lines+markers', name=area))
# 設定圖表標題和軸標籤
fig.update_layout(
#title='各地區收入變化',
xaxis_title='年份',
yaxis_title='收入 (元)',
hovermode='x',
width=700 # 設定圖表寬度
)
# 在 Streamlit 中顯示圖表
st.plotly_chart(fig,use_container_width=True)
st.write('### 原始資料')
st.write(df)
##############################################################
st.write('### ########################################')
st.write('# 帕金森氏症預測')
st.write("### 數據集: UCI Parkinsons Data Set(帕金森氏症數據集)")
st.image("/Users/xieyuxuan/Desktop/streamlit/1.png")
st.write("### 變數名稱與註解")
st.image("/Users/xieyuxuan/Desktop/streamlit/2.png")
st.write("### 使用方法")
st.image("/Users/xieyuxuan/Desktop/streamlit/3.png")
col_1, col_2,col_3, col_4 = st.columns(4)
with col_1:
st.write('隨機森林是將所有變數依照重要性程度進行排序,能方便篩選變數。')
with col_2:
st.write('將決策邊界和最接近該平面的訓練樣本之距離最大化,縮小分類器的泛化誤差,避免發生模型過度適合的狀況發生。')
with col_3:
st.write('遵循人類神經系統原理,學習並進行數據預測。首先學習,然後利用權重存儲數據,並使用算法來調整權重並減少訓練過程中的偏差。')
with col_4:
st.write('捲積神經網路,透過捲積的概念將資料進行堆疊、分類,展開後進行預測,能提升準確率。')
st.write("### 目的:推判哪些變數與是否得病相關性較高")
col_5, col_6 = st.columns((7,3))
with col_5:
st.image("/Users/xieyuxuan/Desktop/streamlit/4.png")
with col_6:
st.write("### ")
st.write("### ")
st.write("### 載入套件")
col_7, col_8 = st.columns((3,7))
with col_7:
st.write("### ")
st.write('### 讀檔、進行分類及資料標準化')
with col_8:
st.image("/Users/xieyuxuan/Desktop/streamlit/5.png")
col_9, col_10 = st.columns((7,3))
with col_9:
st.image("/Users/xieyuxuan/Desktop/streamlit/6.png")
with col_10:
st.write("### ")
st.write("### Random Forest:查看各變數之重要性並排序。")
col_11, col_12 = st.columns(2)
with col_11:
st.image("/Users/xieyuxuan/Desktop/streamlit/7.png")
with col_12:
st.image("/Users/xieyuxuan/Desktop/streamlit/8.png")
st.write("### SVM")
st.image("/Users/xieyuxuan/Desktop/streamlit/9.png")
col_13, col_14 = st.columns((6,4))
with col_13:
st.image("/Users/xieyuxuan/Desktop/streamlit/10.png")
with col_14:
st.write("## ")
st.write("### 準確率:79.48%")
st.write("### MLP")
st.image("/Users/xieyuxuan/Desktop/streamlit/11.png")
col_15, col_16 = st.columns((6,4))
with col_15:
st.image("/Users/xieyuxuan/Desktop/streamlit/12.png")
with col_16:
st.write("## ")
st.write("### 準確率:87.17%")
st.write("### CNN+MLP")
st.image("/Users/xieyuxuan/Desktop/streamlit/13.png")
col_17, col_18 = st.columns((6,4))
with col_17:
st.image("/Users/xieyuxuan/Desktop/streamlit/14.png")
with col_18:
st.write("## ")
st.write("### 準確率:89.74%")
st.write("### 結論")
st.write("### 透過SVM、CNN、MLP等方法進行分析預測後,發現基頻變化的非線性測量、人聲基頻、非線性動態複雜度…等等與基頻相關的變數都與預測結果較相關,所以我們推測能從聲音頻率變化來初步推判這個人是否患有帕金森氏症。")
##############################################################
st.write('### ########################################')
st.write('# 子宮頸癌行為風險預測')
st.write("### 數據集: UCI子宮頸癌行為風險資料集 (19個變數;72筆資料)")
st.image("/Users/xieyuxuan/Desktop/streamlit/16.png")
st.write("### 資料介紹")
st.image("/Users/xieyuxuan/Desktop/streamlit/15.png")
st.write("### 目的:藉由主成分分析查看資料中哪些變數為主要變數,再利用判別分析查看新變數與是否患有子宮頸癌的相關性。推斷出哪些原因可能罹患子宮頸癌,並給予建議。")
st.write("### 主成分分析")
col_19, col_20 = st.columns((7,3))
with col_19:
st.image("/Users/xieyuxuan/Desktop/streamlit/17.png")
with col_20:
st.write("## ")
st.write("### 取前3個(因為趨近於平緩代表變異差異不大)")
st.write("### 取5個可以解釋近八成以上的變異")
st.image("/Users/xieyuxuan/Desktop/streamlit/18.png")
st.image("/Users/xieyuxuan/Desktop/streamlit/19.png")
st.image("/Users/xieyuxuan/Desktop/streamlit/20.png")
st.image("/Users/xieyuxuan/Desktop/streamlit/21.png")
st.image("/Users/xieyuxuan/Desktop/streamlit/22.png")
st.image("/Users/xieyuxuan/Desktop/streamlit/23.png")
st.write("### 判別分析")
col_21, col_22 = st.columns(2)
with col_21:
st.image("/Users/xieyuxuan/Desktop/streamlit/24.png")
with col_22:
st.write("### ")
st.write("X5、X2主成分對罹患子宮頸癌呈現負相關,相關係數較大、影響力較大→衛生習慣、飲食習慣越差的人,通常配合度越高,越希望透過治療改善狀況;越自律的人,心態越樂觀→得病率越低")
st.image("/Users/xieyuxuan/Desktop/streamlit/25.png")
st.write("### 用原資料建模")
st.image("/Users/xieyuxuan/Desktop/streamlit/26.png")
col_23, col_24 = st.columns((7,3))
with col_23:
st.write("### ")
with col_24:
st.image("/Users/xieyuxuan/Desktop/streamlit/28.png")
st.write("### 用主成份建模")
st.image("/Users/xieyuxuan/Desktop/streamlit/30.png")
col_25, col_26 = st.columns((7,3))
with col_25:
st.write("### ")
with col_26:
st.image("/Users/xieyuxuan/Desktop/streamlit/31.png")
st.write("### 結論")
st.write("### 子宮頸癌發生率的排名為女性癌症第一位,發現壓力及不當飲食習慣及衛生習慣可能是造成罹患子宮頸癌機率升高的原因,所以健康的飲食習慣、保持樂觀的態度,適當抒發壓力,能降低罹患風險。")
st.write("### 用原資料建模產生的誤判率較低,可能原因是因為我們只取了前五個主成分來做,有些變數是在其他主成分較為重要。")
##############################################################
st.write('### ########################################')
st.write('# 白內障智能檢測')
st.write("### 數據集: kaggle眼部疾病智能識別")
st.image("/Users/xieyuxuan/Desktop/streamlit/50.png")
st.write("### 目的:利用深度學習演算法進行判讀,幫助醫生對患者進行初步評估。")
st.write("### ")
st.write("## 使用方法")
st.write("### 使用InceptionV3、ResNet152、InceptionResNetV2、VGG19四種演算法,比較其優劣,綜合種種比較尋找出最適合此資料之AI模型。")
st.write("### ")
st.write("### 切割測試集、訓練集(比例8:2)")
st.image("/Users/xieyuxuan/Desktop/streamlit/51.png")
st.write("### ")
st.write("## InceptionV3")
st.image("/Users/xieyuxuan/Desktop/streamlit/52.png")
st.image("/Users/xieyuxuan/Desktop/streamlit/53.png")
st.write("### ")
st.write("## ResNet152")
st.image("/Users/xieyuxuan/Desktop/streamlit/54.png")
st.image("/Users/xieyuxuan/Desktop/streamlit/55.png")
st.write("### ")
st.write("## InceptionResNetV2")
st.image("/Users/xieyuxuan/Desktop/streamlit/56.png")
st.image("/Users/xieyuxuan/Desktop/streamlit/57.png")
st.write("### ")
st.write("## IVGG19")
st.image("/Users/xieyuxuan/Desktop/streamlit/58.png")
st.image("/Users/xieyuxuan/Desktop/streamlit/59.png")
st.write("### 結論")
st.write("### 以這份資料為例,綜合以上模型比較,VGG19和ResNet152在模型的性能表現上有較好的發揮,故可使用VGG19和ResNet152兩演算法作為輔助醫生判讀眼球是否有疾病的演算法指標。")
st.write("### 但依現行法律而言,還是需要醫生的進一步鑑定,這演算法還只能為輔助工具幫助醫生二次確認,以減少醫學誤判的機率。")