def _evaluate_individual(self, ind_params): param_dict = self._to_param_dict(ind_params) learner_obj = self.learner(**param_dict) score = 0 for train_ind, val_ind in self.indices: x_train, y_train = IMAHAKIL().fit_sample(self.X[train_ind, :], self.y[train_ind]) learner_obj.fit(x_train,y_train) score += self.fitness_func(learner_obj.predict(self.X[val_ind, :]), self.y[val_ind]) return score / self.num_folds
import numpy as np from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score from sklearn.model_selection import train_test_split from sklearn import naive_bayes from sklearn import linear_model from Imahakil import IMAHAKIL dataset = np.loadtxt('I:\\tools\\SoftwarePrediction\\dataset\\pc1.txt', delimiter=",") length = len(dataset[0]) x = dataset[:, 0:length - 1] y = dataset[:, length - 1] x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.4) x_train, y_train = IMAHAKIL().fit_sample(x_train, y_train) clf = linear_model.LogisticRegression(solver='liblinear') clf.fit(x_train, y_train) y_pred = clf.predict(x_test) # count=0 # # for i in range(len(result)): # # if result[i]==y_test[i]: # # count=count+1 # # print(count/len(result)) print("acc", accuracy_score(y_test, y_pred)) for i in range(len(y_pred)): if y_test[i] == 1 and y_pred[i] == 1: print(i) print("precision", precision_score(y_test, y_pred))
print("f1", f1.mean()) print("gMean", gMean.mean()) ################################################################################# acc = [] precision = [] recall = [] f1 = [] gMean = [] matrix = [] #random_state 3,8 #x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.4,random_state=20) #x_train, y_train = BorderlineOverSampling(x_train, y_train, 0.5, 10).sampling() #x_train, y_train = Adasyn(x_train, y_train, 0.5, 10).sampling() #x_train, y_train = MAHAKIL().fit_sample(x_train, y_train) x_train, y_train = IMAHAKIL(pfp).fit_sample(before_x_train, before_y_train) doc.write( "\n" + "\n" + "\n" + "\n" + "\n" + "##################################IMAHAKIL############################################" + "\n") for i in range(len(x_train)): for j in range(len(x_train[i])): doc.write(str(round(x_train[i][j], 2)) + ",") doc.write(str(y_train[i]) + "\n") #x_train, y_train = Smote(x_train, y_train, 50, 10).over_sampling() clf.fit(x_train, y_train) y_pred = clf.predict(x_test)