Spaces:
Running
Running
Adding option to choose keywords.
Browse files- pages/3 Bidirected Network.py +23 -14
pages/3 Bidirected Network.py
CHANGED
@@ -165,24 +165,32 @@ if uploaded_file is not None:
|
|
165 |
def freqitem(extype):
|
166 |
freq_item = fpgrowth(df, min_support=supp, use_colnames=True, max_len=maxlen)
|
167 |
return freq_item
|
168 |
-
|
169 |
-
@st.cache_data(ttl=3600)
|
170 |
-
def arm_table(extype):
|
171 |
-
res = association_rules(freq_item, metric='confidence', min_threshold=conf)
|
172 |
-
res = res[['antecedents', 'consequents', 'antecedent support', 'consequent support', 'support', 'confidence', 'lift', 'conviction']]
|
173 |
-
res['antecedents'] = res['antecedents'].apply(lambda x: ', '.join(list(x))).astype('unicode')
|
174 |
-
res['consequents'] = res['consequents'].apply(lambda x: ', '.join(list(x))).astype('unicode')
|
175 |
-
restab = res
|
176 |
-
return res, restab
|
177 |
|
178 |
freq_item = freqitem(extype)
|
179 |
-
|
|
|
|
|
|
|
|
|
180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
if freq_item.empty:
|
182 |
st.error('Please lower your value.', icon="π¨")
|
183 |
else:
|
184 |
-
|
185 |
-
st.
|
|
|
186 |
|
187 |
#===visualize===
|
188 |
|
@@ -191,8 +199,8 @@ if uploaded_file is not None:
|
|
191 |
@st.cache_data(ttl=3600)
|
192 |
def map_node(extype):
|
193 |
res['to'] = res['antecedents'] + ' β ' + res['consequents'] + '\n Support = ' + res['support'].astype(str) + '\n Confidence = ' + res['confidence'].astype(str) + '\n Conviction = ' + res['conviction'].astype(str)
|
194 |
-
res_ant = res[['antecedents','antecedent support']].rename(columns={'antecedents': 'node', 'antecedent support': 'size'})
|
195 |
-
res_con = res[['consequents','consequent support']].rename(columns={'consequents': 'node', 'consequent support': 'size'})
|
196 |
res_node = pd.concat([res_ant, res_con]).drop_duplicates(keep='first')
|
197 |
return res_node, res
|
198 |
|
@@ -239,6 +247,7 @@ if uploaded_file is not None:
|
|
239 |
config=config)
|
240 |
time.sleep(1)
|
241 |
st.toast('Process completed', icon='π')
|
|
|
242 |
with tab2:
|
243 |
st.markdown('**Santosa, F. A. (2023). Adding Perspective to the Bibliometric Mapping Using Bidirected Graph. Open Information Science, 7(1), 20220152.** https://doi.org/10.1515/opis-2022-0152')
|
244 |
|
|
|
165 |
def freqitem(extype):
|
166 |
freq_item = fpgrowth(df, min_support=supp, use_colnames=True, max_len=maxlen)
|
167 |
return freq_item
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
|
169 |
freq_item = freqitem(extype)
|
170 |
+
col1, col2 = st.columns(2)
|
171 |
+
with col1:
|
172 |
+
st.write('π¨ The more data you have, the longer you will have to wait.')
|
173 |
+
with col2:
|
174 |
+
showall = st.checkbox('Show all nodes', value=True, on_change=reset_all)
|
175 |
|
176 |
+
@st.cache_data(ttl=3600)
|
177 |
+
def arm_table(extype):
|
178 |
+
restab = association_rules(freq_item, metric='confidence', min_threshold=conf)
|
179 |
+
restab = restab[['antecedents', 'consequents', 'antecedent support', 'consequent support', 'support', 'confidence', 'lift', 'conviction']]
|
180 |
+
restab['antecedents'] = restab['antecedents'].apply(lambda x: ', '.join(list(x))).astype('unicode')
|
181 |
+
restab['consequents'] = restab['consequents'].apply(lambda x: ', '.join(list(x))).astype('unicode')
|
182 |
+
if showall:
|
183 |
+
restab['Show'] = True
|
184 |
+
else:
|
185 |
+
restab['Show'] = False
|
186 |
+
return restab
|
187 |
+
|
188 |
if freq_item.empty:
|
189 |
st.error('Please lower your value.', icon="π¨")
|
190 |
else:
|
191 |
+
restab = arm_table(extype)
|
192 |
+
restab = st.data_editor(restab, use_container_width=True)
|
193 |
+
res = restab[restab['Show'] == True]
|
194 |
|
195 |
#===visualize===
|
196 |
|
|
|
199 |
@st.cache_data(ttl=3600)
|
200 |
def map_node(extype):
|
201 |
res['to'] = res['antecedents'] + ' β ' + res['consequents'] + '\n Support = ' + res['support'].astype(str) + '\n Confidence = ' + res['confidence'].astype(str) + '\n Conviction = ' + res['conviction'].astype(str)
|
202 |
+
res_ant = res[['antecedents','antecedent support']].rename(columns={'antecedents': 'node', 'antecedent support': 'size'})
|
203 |
+
res_con = res[['consequents','consequent support']].rename(columns={'consequents': 'node', 'consequent support': 'size'})
|
204 |
res_node = pd.concat([res_ant, res_con]).drop_duplicates(keep='first')
|
205 |
return res_node, res
|
206 |
|
|
|
247 |
config=config)
|
248 |
time.sleep(1)
|
249 |
st.toast('Process completed', icon='π')
|
250 |
+
|
251 |
with tab2:
|
252 |
st.markdown('**Santosa, F. A. (2023). Adding Perspective to the Bibliometric Mapping Using Bidirected Graph. Open Information Science, 7(1), 20220152.** https://doi.org/10.1515/opis-2022-0152')
|
253 |
|