Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3. import os
  4.  
  5. from sklearn.datasets import load_iris
  6. from sklearn.feature_selection import SelectKBest
  7. from sklearn.feature_selection import f_classif
  8. from sklearn.model_selection import RepeatedStratifiedKFold
  9. from sklearn.neural_network import MLPClassifier
  10.  
  11. features_dic = {}
  12. results_dic = {}
  13.  
  14. script_dir = os.path.dirname(__file__)
  15. rel_path = "bialaczka_switched.xls"
  16. abs_file_path = os.path.join(script_dir, rel_path)
  17.  
  18. dataExcel = pd.read_excel(abs_file_path, nrows=410)
  19. df = pd.DataFrame(dataExcel)
  20.  
  21. feature_data = df.iloc[:, :-2]
  22. diagnose_classes = np.array(df['Klasa'])
  23.  
  24. # Create an SelectKBest object to select features with two best ANOVA F-Values
  25. fvalue_selector = SelectKBest(f_classif)
  26.  
  27. # Apply the SelectKBest object to the features and target
  28. feature_data_kbest = fvalue_selector.fit(feature_data, diagnose_classes)
  29.  
  30. ranking = fvalue_selector.scores_
  31.  
  32. ranking_ = pd.DataFrame(ranking)
  33.  
  34. X = fvalue_selector.transform(feature_data)
  35. y = diagnose_classes
  36.  
  37.  
  38. rskf = RepeatedStratifiedKFold(n_splits=2, n_repeats=2,
  39. random_state= 36851234)
  40. for train_index, test_index in rskf.split(X, y):
  41. # print("TRAIN:", train_index, "TEST:", test_index)
  42. X_train, X_test = X[train_index], X[test_index]
  43. y_train, y_test = y[train_index], y[test_index]
  44.  
  45. clf = MLPClassifier(hidden_layer_sizes=(100), max_iter=600, alpha=0.0001,
  46. solver='sgd',learning_rate='constant',momentum =0,
  47. learning_rate_init=0.2, verbose=10, random_state=21,tol=0.000000001)
  48.  
  49. clf.fit(X_train, y_train)
  50. y_pred = clf.predict(X_test)
  51.  
  52. print(y_pred)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement