Spaces:
Runtime error
Runtime error
Upload 9 files
Browse files- .gitattributes +1 -0
- Procfile +1 -0
- app.py +73 -0
- requirements.txt +6 -0
- setup.sh +13 -0
- star_classification.csv +3 -0
- stellar_clf.pkl +3 -0
- stellar_model.ipynb +245 -0
.gitattributes
CHANGED
@@ -29,3 +29,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
29 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
30 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
31 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
29 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
30 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
31 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
32 |
+
star_classification.csv filter=lfs diff=lfs merge=lfs -text
|
Procfile
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
web: sh setup.sh && streamlit run app.py
|
app.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import pickle
|
5 |
+
import base64
|
6 |
+
import seaborn as sns
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
|
9 |
+
st.write("""
|
10 |
+
# Stellar Detection App
|
11 |
+
|
12 |
+
Stellar detection App adalah aplikasi untuk mendeteksi bintang star dan galaxy.
|
13 |
+
|
14 |
+
Aplikasi ini mendeteksi bintang menggunakan data Stellar Classification.
|
15 |
+
|
16 |
+
""")
|
17 |
+
|
18 |
+
url_dataset = f'<a href="churn_data.csv">Download Dataset CSV File</a>'
|
19 |
+
st.markdown(url_dataset, unsafe_allow_html=True)
|
20 |
+
|
21 |
+
def user_input_features() :
|
22 |
+
alpha = st.sidebar.slider('Alpha', 0.005528,359.99981)
|
23 |
+
delta = st.sidebar.slider('Delta', -18.785328,83.000519)
|
24 |
+
u = st.sidebar.slider('U', -9999.0,32.78139)
|
25 |
+
g = st.sidebar.slider('G', -9999.0,31.60224)
|
26 |
+
r = st.sidebar.slider('R', 9.82207,29.57186)
|
27 |
+
i = st.sidebar.slider('I', 9.469903,32.14147)
|
28 |
+
z = st.sidebar.slider('Z', -9999.0,29.38374)
|
29 |
+
redshift = st.sidebar.slider('Redshift', -0.009971,7.011245)
|
30 |
+
|
31 |
+
data = {'alpha':[alpha],
|
32 |
+
'delta':[delta],
|
33 |
+
'u':[u],
|
34 |
+
'g':[g],
|
35 |
+
'r':[r],
|
36 |
+
'i':[i],
|
37 |
+
'z':[z],
|
38 |
+
'redshift':[redshift]}
|
39 |
+
|
40 |
+
features = pd.DataFrame(data)
|
41 |
+
return features
|
42 |
+
|
43 |
+
input_df = user_input_features()
|
44 |
+
|
45 |
+
|
46 |
+
star_raw = pd.read_csv('star_classification.csv')
|
47 |
+
star_raw.fillna(0, inplace=True)
|
48 |
+
star = star_raw.drop(columns=['class'])
|
49 |
+
df = pd.concat([input_df,star],axis=0)
|
50 |
+
|
51 |
+
|
52 |
+
df = df[:1] # Selects only the first row (the user input data)
|
53 |
+
df.fillna(0, inplace=True)
|
54 |
+
|
55 |
+
features = ['alpha', 'delta', 'u', 'g', 'r', 'i', 'z', 'redshift']
|
56 |
+
|
57 |
+
df = df[features]
|
58 |
+
|
59 |
+
|
60 |
+
st.subheader('User Input features')
|
61 |
+
st.write(df)
|
62 |
+
|
63 |
+
load_clf = pickle.load(open('stellar_clf.pkl', 'rb'))
|
64 |
+
detect = load_clf.predict(df)
|
65 |
+
detect_proba = load_clf.predict_proba(df)
|
66 |
+
star_labels = np.array(['Not Star','Star'])
|
67 |
+
st.subheader('Detection')
|
68 |
+
st.write(star_labels[detect[0]])
|
69 |
+
st.subheader('Detection Probability')
|
70 |
+
df_prob = pd.DataFrame(data = detect_proba,
|
71 |
+
index = ['Probability'],
|
72 |
+
columns = star_labels)
|
73 |
+
st.write(df_prob)
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
matplotlib==3.5.1
|
2 |
+
numpy==1.21.5
|
3 |
+
pandas==1.4.2
|
4 |
+
seaborn==0.11.2
|
5 |
+
streamlit==1.13.0
|
6 |
+
sklearn
|
setup.sh
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
mkdir -p ~/.streamlit/
|
2 |
+
|
3 |
+
echo "\
|
4 |
+
[general]\n\
|
5 |
+
email = \"your-email@domain.com\"\n\
|
6 |
+
" > ~/.streamlit/credentials.toml
|
7 |
+
|
8 |
+
echo "\
|
9 |
+
[server]\n\
|
10 |
+
headless = true\n\
|
11 |
+
enableCORS=false\n\
|
12 |
+
port = $PORT\n\
|
13 |
+
" > ~/.streamlit/config.toml
|
star_classification.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:faefcad9b950309282024dd351289ee14ae30f65a7b2ef32c9fa442da9dbe585
|
3 |
+
size 16755863
|
stellar_clf.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dbfd151d9ca61bb1ce0f76a575962b5b141f7d9721749699214da4b23ae2e03d
|
3 |
+
size 6761510
|
stellar_model.ipynb
ADDED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
|
3 |
+
{
|
4 |
+
"cell_type": "markdown",
|
5 |
+
"id": "c2f352ed",
|
6 |
+
"metadata": {},
|
7 |
+
"source": [
|
8 |
+
"# Dataset\n",
|
9 |
+
"\n",
|
10 |
+
"https://www.kaggle.com/datasets/fedesoriano/stellar-classification-dataset-sdss17?resource=download"
|
11 |
+
]
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"cell_type": "code",
|
15 |
+
"execution_count": 2,
|
16 |
+
"id": "dff0477d",
|
17 |
+
"metadata": {},
|
18 |
+
"outputs": [],
|
19 |
+
"source": [
|
20 |
+
"import pandas as pd \n",
|
21 |
+
"from sklearn.ensemble import RandomForestClassifier\n",
|
22 |
+
"import pickle"
|
23 |
+
]
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"cell_type": "code",
|
27 |
+
"execution_count": 3,
|
28 |
+
"id": "53a8cd69",
|
29 |
+
"metadata": {},
|
30 |
+
"outputs": [
|
31 |
+
{
|
32 |
+
"name": "stdout",
|
33 |
+
"output_type": "stream",
|
34 |
+
"text": [
|
35 |
+
" obj_ID alpha delta u g r \\\n",
|
36 |
+
"0 1.237661e+18 135.689107 32.494632 23.87882 22.27530 20.39501 \n",
|
37 |
+
"1 1.237665e+18 144.826101 31.274185 24.77759 22.83188 22.58444 \n",
|
38 |
+
"2 1.237661e+18 142.188790 35.582444 25.26307 22.66389 20.60976 \n",
|
39 |
+
"3 1.237663e+18 338.741038 -0.402828 22.13682 23.77656 21.61162 \n",
|
40 |
+
"4 1.237680e+18 345.282593 21.183866 19.43718 17.58028 16.49747 \n",
|
41 |
+
"\n",
|
42 |
+
" i z run_ID rerun_ID cam_col field_ID spec_obj_ID \\\n",
|
43 |
+
"0 19.16573 18.79371 3606 301 2 79 6.543777e+18 \n",
|
44 |
+
"1 21.16812 21.61427 4518 301 5 119 1.176014e+19 \n",
|
45 |
+
"2 19.34857 18.94827 3606 301 2 120 5.152200e+18 \n",
|
46 |
+
"3 20.50454 19.25010 4192 301 3 214 1.030107e+19 \n",
|
47 |
+
"4 15.97711 15.54461 8102 301 3 137 6.891865e+18 \n",
|
48 |
+
"\n",
|
49 |
+
" class redshift plate MJD fiber_ID \n",
|
50 |
+
"0 GALAXY 0.634794 5812 56354 171 \n",
|
51 |
+
"1 GALAXY 0.779136 10445 58158 427 \n",
|
52 |
+
"2 GALAXY 0.644195 4576 55592 299 \n",
|
53 |
+
"3 GALAXY 0.932346 9149 58039 775 \n",
|
54 |
+
"4 GALAXY 0.116123 6121 56187 842 \n"
|
55 |
+
]
|
56 |
+
}
|
57 |
+
],
|
58 |
+
"source": [
|
59 |
+
"pd.set_option('display.max_columns', None)\n",
|
60 |
+
"pd.set_option('display.max_rows', None)\n",
|
61 |
+
"df_star = pd.read_csv('star_classification.csv')\n",
|
62 |
+
"print(df_star.head())"
|
63 |
+
]
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"cell_type": "code",
|
67 |
+
"execution_count": 4,
|
68 |
+
"id": "55f05a40",
|
69 |
+
"metadata": {},
|
70 |
+
"outputs": [
|
71 |
+
{
|
72 |
+
"data": {
|
73 |
+
"text/plain": [
|
74 |
+
"Index(['obj_ID', 'alpha', 'delta', 'u', 'g', 'r', 'i', 'z', 'run_ID',\n",
|
75 |
+
" 'rerun_ID', 'cam_col', 'field_ID', 'spec_obj_ID', 'class', 'redshift',\n",
|
76 |
+
" 'plate', 'MJD', 'fiber_ID'],\n",
|
77 |
+
" dtype='object')"
|
78 |
+
]
|
79 |
+
},
|
80 |
+
"execution_count": 4,
|
81 |
+
"metadata": {},
|
82 |
+
"output_type": "execute_result"
|
83 |
+
}
|
84 |
+
],
|
85 |
+
"source": [
|
86 |
+
"df_star.columns"
|
87 |
+
]
|
88 |
+
},
|
89 |
+
{
|
90 |
+
"cell_type": "code",
|
91 |
+
"execution_count": 5,
|
92 |
+
"id": "e468f78d",
|
93 |
+
"metadata": {},
|
94 |
+
"outputs": [
|
95 |
+
{
|
96 |
+
"data": {
|
97 |
+
"text/plain": [
|
98 |
+
"obj_ID 1237645942904389888.0\n",
|
99 |
+
"alpha 0.005528\n",
|
100 |
+
"delta -18.785328\n",
|
101 |
+
"u -9999.0\n",
|
102 |
+
"g -9999.0\n",
|
103 |
+
"r 9.82207\n",
|
104 |
+
"i 9.469903\n",
|
105 |
+
"z -9999.0\n",
|
106 |
+
"run_ID 109\n",
|
107 |
+
"rerun_ID 301\n",
|
108 |
+
"cam_col 1\n",
|
109 |
+
"field_ID 11\n",
|
110 |
+
"spec_obj_ID 299519089380976640.0\n",
|
111 |
+
"class GALAXY\n",
|
112 |
+
"redshift -0.009971\n",
|
113 |
+
"plate 266\n",
|
114 |
+
"MJD 51608\n",
|
115 |
+
"fiber_ID 1\n",
|
116 |
+
"dtype: object"
|
117 |
+
]
|
118 |
+
},
|
119 |
+
"execution_count": 5,
|
120 |
+
"metadata": {},
|
121 |
+
"output_type": "execute_result"
|
122 |
+
}
|
123 |
+
],
|
124 |
+
"source": [
|
125 |
+
"df_star.min()"
|
126 |
+
]
|
127 |
+
},
|
128 |
+
{
|
129 |
+
"cell_type": "code",
|
130 |
+
"execution_count": 6,
|
131 |
+
"id": "e1b7eff1",
|
132 |
+
"metadata": {},
|
133 |
+
"outputs": [
|
134 |
+
{
|
135 |
+
"data": {
|
136 |
+
"text/plain": [
|
137 |
+
"obj_ID 1237680531356386304.0\n",
|
138 |
+
"alpha 359.99981\n",
|
139 |
+
"delta 83.000519\n",
|
140 |
+
"u 32.78139\n",
|
141 |
+
"g 31.60224\n",
|
142 |
+
"r 29.57186\n",
|
143 |
+
"i 32.14147\n",
|
144 |
+
"z 29.38374\n",
|
145 |
+
"run_ID 8162\n",
|
146 |
+
"rerun_ID 301\n",
|
147 |
+
"cam_col 6\n",
|
148 |
+
"field_ID 989\n",
|
149 |
+
"spec_obj_ID 14126940609093851136.0\n",
|
150 |
+
"class STAR\n",
|
151 |
+
"redshift 7.011245\n",
|
152 |
+
"plate 12547\n",
|
153 |
+
"MJD 58932\n",
|
154 |
+
"fiber_ID 1000\n",
|
155 |
+
"dtype: object"
|
156 |
+
]
|
157 |
+
},
|
158 |
+
"execution_count": 6,
|
159 |
+
"metadata": {},
|
160 |
+
"output_type": "execute_result"
|
161 |
+
}
|
162 |
+
],
|
163 |
+
"source": [
|
164 |
+
"df_star.max()"
|
165 |
+
]
|
166 |
+
},
|
167 |
+
{
|
168 |
+
"cell_type": "code",
|
169 |
+
"execution_count": 7,
|
170 |
+
"id": "aba35ef0",
|
171 |
+
"metadata": {},
|
172 |
+
"outputs": [],
|
173 |
+
"source": [
|
174 |
+
"X = df_star.drop('class', axis=1)\n",
|
175 |
+
"Y = df_star['class']"
|
176 |
+
]
|
177 |
+
},
|
178 |
+
{
|
179 |
+
"cell_type": "code",
|
180 |
+
"execution_count": 8,
|
181 |
+
"id": "ec2e27b9",
|
182 |
+
"metadata": {},
|
183 |
+
"outputs": [
|
184 |
+
{
|
185 |
+
"data": {
|
186 |
+
"text/plain": [
|
187 |
+
"RandomForestClassifier()"
|
188 |
+
]
|
189 |
+
},
|
190 |
+
"execution_count": 8,
|
191 |
+
"metadata": {},
|
192 |
+
"output_type": "execute_result"
|
193 |
+
}
|
194 |
+
],
|
195 |
+
"source": [
|
196 |
+
"clf = RandomForestClassifier()\n",
|
197 |
+
"clf.fit(X, Y)"
|
198 |
+
]
|
199 |
+
},
|
200 |
+
{
|
201 |
+
"cell_type": "code",
|
202 |
+
"execution_count": 9,
|
203 |
+
"id": "0fb83c09",
|
204 |
+
"metadata": {},
|
205 |
+
"outputs": [],
|
206 |
+
"source": [
|
207 |
+
"pickle.dump(clf, open('stellar_clf.pkl', 'wb'))"
|
208 |
+
]
|
209 |
+
},
|
210 |
+
{
|
211 |
+
"cell_type": "code",
|
212 |
+
"execution_count": null,
|
213 |
+
"id": "a6fab8b2",
|
214 |
+
"metadata": {},
|
215 |
+
"outputs": [],
|
216 |
+
"source": []
|
217 |
+
}
|
218 |
+
],
|
219 |
+
"metadata": {
|
220 |
+
"kernelspec": {
|
221 |
+
"display_name": "Python 3 (ipykernel)",
|
222 |
+
"language": "python",
|
223 |
+
"name": "python3"
|
224 |
+
},
|
225 |
+
"language_info": {
|
226 |
+
"codemirror_mode": {
|
227 |
+
"name": "ipython",
|
228 |
+
"version": 3
|
229 |
+
},
|
230 |
+
"file_extension": ".py",
|
231 |
+
"mimetype": "text/x-python",
|
232 |
+
"name": "python",
|
233 |
+
"nbconvert_exporter": "python",
|
234 |
+
"pygments_lexer": "ipython3",
|
235 |
+
"version": "3.9.12"
|
236 |
+
},
|
237 |
+
"vscode": {
|
238 |
+
"interpreter": {
|
239 |
+
"hash": "a07fda4108288eac30d110fb6c0835906d2e1f106803cd94f31ab0c859b7a7bd"
|
240 |
+
}
|
241 |
+
}
|
242 |
+
},
|
243 |
+
"nbformat": 4,
|
244 |
+
"nbformat_minor": 5
|
245 |
+
}
|