Showing
1 changed file
with
8 additions
and
14 deletions
... | @@ -191,39 +191,33 @@ if __name__ == "__main__": | ... | @@ -191,39 +191,33 @@ if __name__ == "__main__": |
191 | print(" Number of testing class I: {}".format(y_test.count('I'))) | 191 | print(" Number of testing class I: {}".format(y_test.count('I'))) |
192 | print(" Shape of testing matrix: {}".format(X_test.shape)) | 192 | print(" Shape of testing matrix: {}".format(X_test.shape)) |
193 | 193 | ||
194 | - jobs = -1 | ||
195 | - paramGrid = [] | ||
196 | - nIter = 20 | ||
197 | - crossV = 10 | ||
198 | - print("Defining randomized grid search...") | ||
199 | if args.classifier == 'SVM': | 194 | if args.classifier == 'SVM': |
200 | # SVM | 195 | # SVM |
201 | - classifier = SVC(args.kernel) | 196 | + myClassifier = SVC(args.kernel) |
202 | - elif args.classifier == 'BernoulliNB': | 197 | + elif args.myClassifier == 'BernoulliNB': |
203 | # BernoulliNB | 198 | # BernoulliNB |
204 | - classifier = BernoulliNB() | 199 | + myClassifier = BernoulliNB() |
205 | elif args.classifier == 'kNN': | 200 | elif args.classifier == 'kNN': |
206 | # kNN | 201 | # kNN |
207 | - k_range = list(range(1, 7, 2)) | 202 | + myClassifier = KNeighborsClassifier() |
208 | - classifier = KNeighborsClassifier() | ||
209 | else: | 203 | else: |
210 | print("Bad classifier") | 204 | print("Bad classifier") |
211 | exit() | 205 | exit() |
212 | print(" Done!") | 206 | print(" Done!") |
213 | 207 | ||
214 | print("Training...") | 208 | print("Training...") |
215 | - classifier.fit(X_train, y_train) | 209 | + myClassifier.fit(X_train, y_train) |
216 | print(" Done!") | 210 | print(" Done!") |
217 | 211 | ||
218 | - y_pred = classifier.predict(X_test) | 212 | + y_pred = myClassifier.predict(X_test) |
219 | - best_parameters = classifier.best_estimator_.get_params() | 213 | + best_parameters = myClassifier.best_estimator_.get_params() |
220 | print(" Done!") | 214 | print(" Done!") |
221 | 215 | ||
222 | print("Saving report...") | 216 | print("Saving report...") |
223 | with open(os.path.join(args.outputReportPath, args.outputReportFile), mode='w', encoding='utf8') as oFile: | 217 | with open(os.path.join(args.outputReportPath, args.outputReportFile), mode='w', encoding='utf8') as oFile: |
224 | oFile.write('********** EVALUATION REPORT **********\n') | 218 | oFile.write('********** EVALUATION REPORT **********\n') |
225 | oFile.write('Reduction: {}\n'.format(args.reduction)) | 219 | oFile.write('Reduction: {}\n'.format(args.reduction)) |
226 | - oFile.write('Classifier: {}\n'.format(args.classifier)) | 220 | + oFile.write('Classifier: {}\n'.format(args.myClassifier)) |
227 | oFile.write('Kernel: {}\n'.format(args.kernel)) | 221 | oFile.write('Kernel: {}\n'.format(args.kernel)) |
228 | oFile.write('Accuracy: {}\n'.format(accuracy_score(y_test, y_pred))) | 222 | oFile.write('Accuracy: {}\n'.format(accuracy_score(y_test, y_pred))) |
229 | oFile.write('Precision: {}\n'.format(precision_score(y_test, y_pred, average='weighted'))) | 223 | oFile.write('Precision: {}\n'.format(precision_score(y_test, y_pred, average='weighted'))) | ... | ... |
-
Please register or login to post a comment