Perform experiment in a leave-one-out style Args: label_func: A function, takes a data point as input and return its target label. estimator: A function, return a classifier which supports 'fit' and 'predict' method
(self, label_func, estimator, ngram_range=(1, 1),
text_feature='', use_text=True, use_frc=False,
dp_filter=lambda dp: True, tokenizer=None,
max_features=None, min_df=1, use_bns=False, k=None,
n_jobs=1, use_description=False, use_comment=False,
use_svm=False, svm_type='linear',
use_rf=False, num_estimators = 100, val_max_features=0.5,
is_jira=False)
| 312 | self.classifiers = {} |
| 313 | |
| 314 | def run(self, label_func, estimator, ngram_range=(1, 1), |
| 315 | text_feature='', use_text=True, use_frc=False, |
| 316 | dp_filter=lambda dp: True, tokenizer=None, |
| 317 | max_features=None, min_df=1, use_bns=False, k=None, |
| 318 | n_jobs=1, use_description=False, use_comment=False, |
| 319 | use_svm=False, svm_type='linear', |
| 320 | use_rf=False, num_estimators = 100, val_max_features=0.5, |
| 321 | is_jira=False): |
| 322 | """Perform experiment in a leave-one-out style |
| 323 | |
| 324 | Args: |
| 325 | label_func: A function, takes a data point as input and |
| 326 | return its target label. |
| 327 | estimator: A function, return a classifier which supports |
| 328 | 'fit' and 'predict' method |
| 329 | ngram_range: A tuple of two integers, specify what range of |
| 330 | ngram to use |
| 331 | text_feature: A string, |
| 332 | can be either 'title' or 'description' or 'comment' for jira issue, |
| 333 | and can be either 'message' or 'subject' for fs patch. |
| 334 | If set to None, then texts will not be used. |
| 335 | use_text: A boolean flag, whether to use text feature |
| 336 | use_frc: A boolean flag, whether to use frc |
| 337 | dp_filter: A function decides which data point to exclude. |
| 338 | tokenizer: A function takes a string and return a list of tokens. |
| 339 | max_features: An int or None. If not None, only consider |
| 340 | top max_features ordered by term frequency across the corpus. |
| 341 | min_df: An int, ignore terms when building vocabulary if their |
| 342 | document frequency is strictly lower than this threshold. |
| 343 | use_bns: A boolean flag, use BNS if True, otherwise use IDF |
| 344 | k: An int, number of top features to keep during feature selection. |
| 345 | """ |
| 346 | self._clean() |
| 347 | |
| 348 | if text_feature == '': |
| 349 | if is_jira: |
| 350 | text_feature = 'title' |
| 351 | else: |
| 352 | text_feature = 'message' |
| 353 | |
| 354 | iss = FeatureLabelExtractor(self.datasets, text_feature, label_func, dp_filter, is_jira) |
| 355 | |
| 356 | for jr in self.file_list: |
| 357 | ofs_list = [ojr for ojr in self.file_list if ojr != jr] |
| 358 | |
| 359 | if is_jira: |
| 360 | train_X, train_y = iss.jira_issue_transform(ofs_list, use_description, use_comment) |
| 361 | test_X, test_y = iss.jira_issue_transform([jr], use_description, use_comment) |
| 362 | else: |
| 363 | train_X, train_y = iss.fs_patch_transform(ofs_list) |
| 364 | test_X, test_y = iss.fs_patch_transform([jr]) |
| 365 | |
| 366 | cv = CountVectorizer(tokenizer=tokenizer, |
| 367 | ngram_range=ngram_range, |
| 368 | max_features=max_features, |
| 369 | min_df=min_df) |
| 370 | |
| 371 | train_X['count'] = cv.fit_transform(train_X['text']) |
nothing calls this directly
no test coverage detected