Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- import os
- from sklearn.datasets import load_iris
- from sklearn.feature_selection import SelectKBest
- from sklearn.feature_selection import f_classif
- from sklearn.model_selection import RepeatedStratifiedKFold
- from sklearn.neural_network import MLPClassifier
- features_dic = {}
- results_dic = {}
- script_dir = os.path.dirname(__file__)
- rel_path = "bialaczka_switched.xls"
- abs_file_path = os.path.join(script_dir, rel_path)
- dataExcel = pd.read_excel(abs_file_path, nrows=410)
- df = pd.DataFrame(dataExcel)
- feature_data = df.iloc[:, :-2]
- diagnose_classes = np.array(df['Klasa'])
- # Create an SelectKBest object to select features with two best ANOVA F-Values
- fvalue_selector = SelectKBest(f_classif)
- # Apply the SelectKBest object to the features and target
- feature_data_kbest = fvalue_selector.fit(feature_data, diagnose_classes)
- ranking = fvalue_selector.scores_
- ranking_ = pd.DataFrame(ranking)
- X = fvalue_selector.transform(feature_data)
- y = diagnose_classes
- rskf = RepeatedStratifiedKFold(n_splits=2, n_repeats=2,
- random_state= 36851234)
- for train_index, test_index in rskf.split(X, y):
- # print("TRAIN:", train_index, "TEST:", test_index)
- X_train, X_test = X[train_index], X[test_index]
- y_train, y_test = y[train_index], y[test_index]
- clf = MLPClassifier(hidden_layer_sizes=(100), max_iter=600, alpha=0.0001,
- solver='sgd',learning_rate='constant',momentum =0,
- learning_rate_init=0.2, verbose=10, random_state=21,tol=0.000000001)
- clf.fit(X_train, y_train)
- y_pred = clf.predict(X_test)
- print(y_pred)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement