Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3. import os
  4.  
  5.  
  6. from sklearn.feature_selection import SelectKBest
  7. from sklearn.feature_selection import f_classif
  8.  
  9. features_dic = {}
  10. results_dic = {}
  11.  
  12. script_dir = os.path.dirname(__file__)
  13. rel_path = "dane_zawaly.xlsx"
  14. abs_file_path = os.path.join(script_dir, rel_path)
  15.  
  16. dataExcel = pd.read_excel(abs_file_path, nrows=901)
  17. df = pd.DataFrame(dataExcel)
  18. # print(df)
  19.  
  20.  
  21. feature_data = df.iloc[:, :-1]
  22. diagnose_classes = np.array(df['Klasa'])
  23.  
  24.  
  25. # Create an SelectKBest object to select features with two best ANOVA F-Values
  26. fvalue_selector = SelectKBest(f_classif)
  27.  
  28. # Apply the SelectKBest object to the features and target
  29. feature_data_kbest = fvalue_selector.fit(feature_data, diagnose_classes)
  30.  
  31. # print('Original number of features:', feature_data.shape[1])
  32. # print('Reduced number of features:', feature_data_kbest.shape[1])
  33. # print('Klasy', feature_data_kbest)
  34. ranking = fvalue_selector.scores_
  35.  
  36. ranking_ulepszony = pd.DataFrame(ranking)
  37. # ranking_ulepszony.insert(1, 'Numer cechy', pd.DataFrame(list(range(1,60))))
  38. # ranking_ulepszony.sort_values(ranking_ulepszony[0])
  39.  
  40. print(ranking_ulepszony)
  41.  
  42. # print(ranking)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement