Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from warnings import filterwarnings
|
2 |
+
filterwarnings("ignore")
|
3 |
+
import h5py
|
4 |
+
import numpy as np
|
5 |
+
import pandas as pd
|
6 |
+
#f=h5py.File('/content/drive/MyDrive/inputCONFIG02h2NOISE3-5000.mat','r')
|
7 |
+
#mat=scipy.io.loadmat('/content/drive/MyDrive/inputCONFIG02h2NOISE3-5000.mat')
|
8 |
+
with h5py.File('inputCONFIG02h2NOISE3-5000.mat','r') as file:
|
9 |
+
for key in file.keys():
|
10 |
+
print (key)
|
11 |
+
data=file['Rdnoise'] [:]
|
12 |
+
print(data)
|
13 |
+
print (len(data))
|
14 |
+
data_frame=pd.DataFrame(data)
|
15 |
+
#data_frame.to_csv('data_frame_KH.csv')
|
16 |
+
|
17 |
+
#---------------------------------------------------------------------------
|
18 |
+
import pandas as pd
|
19 |
+
|
20 |
+
# تعداد کل فیچرها
|
21 |
+
num_features = 12012
|
22 |
+
# تعداد فیچرها در هر دسته
|
23 |
+
features_per_category = 1000
|
24 |
+
|
25 |
+
# ایجاد لیست جدید برای نام ستونها
|
26 |
+
new_column_names = []
|
27 |
+
|
28 |
+
# حروف الفبا برای دستهبندی
|
29 |
+
categories = 'abcdefghijkm'
|
30 |
+
|
31 |
+
# تولید نامهای جدید
|
32 |
+
for letter in categories:
|
33 |
+
for i in range(0, features_per_category + 1):
|
34 |
+
new_column_names.append(f"{letter}{i}")
|
35 |
+
|
36 |
+
# اطمینان از اینکه تعداد نامهای جدید مطابق با تعداد ستونهاست
|
37 |
+
new_column_names = new_column_names[:num_features]
|
38 |
+
|
39 |
+
# تغییر نام ستونها
|
40 |
+
data_frame.columns = new_column_names
|
41 |
+
|
42 |
+
#-----------------------------------------------------------------------
|
43 |
+
import scipy.io
|
44 |
+
import h5py
|
45 |
+
import numpy as np
|
46 |
+
import pandas as pd
|
47 |
+
#f=h5py.File('/content/drive/MyDrive/inputCONFIG02h2NOISE3-5000.mat','r')
|
48 |
+
#mat=scipy.io.loadmat('/content/drive/MyDrive/inputCONFIG02h2NOISE3-5000.mat')
|
49 |
+
with h5py.File('targetCONFIG02h2NOISE3-5000.mat','r') as file:
|
50 |
+
for key in file.keys():
|
51 |
+
print (key)
|
52 |
+
data=file['re'] [:]
|
53 |
+
print(data)
|
54 |
+
print (len(data))
|
55 |
+
data_frame_T=pd.DataFrame(data)
|
56 |
+
|
57 |
+
#data_frame.to_csv('data_frame_KH.csv')
|
58 |
+
|
59 |
+
|
60 |
+
|
61 |
+
#---------------------------------------------------------------------------------------
|
62 |
+
|
63 |
+
import pandas as pd
|
64 |
+
|
65 |
+
# تعداد کل فیچرها
|
66 |
+
num_features = 116
|
67 |
+
# تعداد فیچرها در هر دسته
|
68 |
+
features_per_category = 116
|
69 |
+
|
70 |
+
# ایجاد لیست جدید برای نام ستونها
|
71 |
+
new_column_names = []
|
72 |
+
|
73 |
+
# حروف الفبا برای دستهبند
|
74 |
+
categories = 't'
|
75 |
+
|
76 |
+
# تولید نامهای جدید
|
77 |
+
for letter in categories:
|
78 |
+
for i in range(1, features_per_category + 1):
|
79 |
+
new_column_names.append(f"{letter}{i}")
|
80 |
+
|
81 |
+
# اطمینان از اینکه تعداد نامهای جدید مطابق با تعداد ستونهاست
|
82 |
+
new_column_names = new_column_names[:num_features]
|
83 |
+
|
84 |
+
# تغییر نام ستونها
|
85 |
+
data_frame_T.columns = new_column_names
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
+
#---------------------------------------------------------------------------
|
90 |
+
|
91 |
+
from sklearn.neighbors import KNeighborsClassifier
|
92 |
+
from mlxtend.feature_selection import SequentialFeatureSelector as SFS
|
93 |
+
|
94 |
+
# Assuming data_frame and data_frame_T are already defined
|
95 |
+
X = data_frame.iloc[:, 0:1002]
|
96 |
+
|
97 |
+
knn = KNeighborsClassifier()
|
98 |
+
# y = data_frame_T[column]
|
99 |
+
# Loop over each column in data_frame_T
|
100 |
+
for column in data_frame_T.columns[80:116]:
|
101 |
+
|
102 |
+
|
103 |
+
y = data_frame_T[column]
|
104 |
+
sfs = SFS(knn,
|
105 |
+
k_features=50,
|
106 |
+
forward=True,
|
107 |
+
floating=False,
|
108 |
+
verbose=2,
|
109 |
+
scoring='accuracy',
|
110 |
+
cv=0)
|
111 |
+
|
112 |
+
sfs = sfs.fit(X, y)
|
113 |
+
|
114 |
+
print(f'Results for target column: {column}')
|
115 |
+
print('Best accuracy score: %.2f' % sfs.k_score_)
|
116 |
+
print('Best subset (indices):', sfs.k_feature_idx_)
|
117 |
+
print('Best subset (corresponding names):', sfs.k_feature_names_)
|
118 |
+
print('-' * 50)
|
119 |
+
|
120 |
+
|
121 |
+
|