|
from warnings import filterwarnings |
|
filterwarnings("ignore") |
|
import h5py |
|
import numpy as np |
|
import pandas as pd |
|
|
|
|
|
with h5py.File('inputCONFIG02h2NOISE3-5000.mat','r') as file: |
|
for key in file.keys(): |
|
print (key) |
|
data=file['Rdnoise'] [:] |
|
print(data) |
|
print (len(data)) |
|
data_frame=pd.DataFrame(data) |
|
|
|
|
|
|
|
import pandas as pd |
|
|
|
|
|
num_features = 12012 |
|
|
|
features_per_category = 1000 |
|
|
|
|
|
new_column_names = [] |
|
|
|
|
|
categories = 'abcdefghijkm' |
|
|
|
|
|
for letter in categories: |
|
for i in range(0, features_per_category + 1): |
|
new_column_names.append(f"{letter}{i}") |
|
|
|
|
|
new_column_names = new_column_names[:num_features] |
|
|
|
|
|
data_frame.columns = new_column_names |
|
|
|
|
|
import scipy.io |
|
import h5py |
|
import numpy as np |
|
import pandas as pd |
|
|
|
|
|
with h5py.File('targetCONFIG02h2NOISE3-5000.mat','r') as file: |
|
for key in file.keys(): |
|
print (key) |
|
data=file['re'] [:] |
|
print(data) |
|
print (len(data)) |
|
data_frame_T=pd.DataFrame(data) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import pandas as pd |
|
|
|
|
|
num_features = 116 |
|
|
|
features_per_category = 116 |
|
|
|
|
|
new_column_names = [] |
|
|
|
|
|
categories = 't' |
|
|
|
|
|
for letter in categories: |
|
for i in range(1, features_per_category + 1): |
|
new_column_names.append(f"{letter}{i}") |
|
|
|
|
|
new_column_names = new_column_names[:num_features] |
|
|
|
|
|
data_frame_T.columns = new_column_names |
|
|
|
|
|
|
|
|
|
|
|
from sklearn.neighbors import KNeighborsClassifier |
|
from mlxtend.feature_selection import SequentialFeatureSelector as SFS |
|
|
|
|
|
X = data_frame.iloc[:, 0:8002] |
|
|
|
knn = KNeighborsClassifier() |
|
|
|
|
|
for column in data_frame_T.columns[80:116]: |
|
|
|
|
|
y = data_frame_T[column] |
|
sfs = SFS(knn, |
|
k_features=50, |
|
forward=True, |
|
floating=False, |
|
verbose=2, |
|
scoring='accuracy', |
|
cv=0) |
|
|
|
sfs = sfs.fit(X, y) |
|
|
|
print(f'Results for target column: {column}') |
|
print('Best accuracy score: %.2f' % sfs.k_score_) |
|
print('Best subset (indices):', sfs.k_feature_idx_) |
|
print('Best subset (corresponding names):', sfs.k_feature_names_) |
|
print('-' * 50) |
|
|
|
|
|
|
|
|