зеркало из https://github.com/mozilla/bugbug.git
Move bug classification code from run.py into a separate script (#829)
This commit is contained in:
Родитель
176c207292
Коммит
cf31198d3e
34
run.py
34
run.py
|
@ -6,8 +6,6 @@
|
|||
import argparse
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
|
||||
from bugbug import bugzilla, db, repository
|
||||
from bugbug.models import MODELS, get_model_class
|
||||
|
||||
|
@ -43,7 +41,6 @@ def parse_args(args):
|
|||
choices=["default", "nn"],
|
||||
default="default",
|
||||
)
|
||||
parser.add_argument("--classify", help="Perform evaluation", action="store_true")
|
||||
parser.add_argument(
|
||||
"--historical",
|
||||
help="""Analyze historical bugs. Only used for defect, bugtype,
|
||||
|
@ -54,10 +51,6 @@ def parse_args(args):
|
|||
|
||||
|
||||
def main(args):
|
||||
model_file_name = "{}{}model".format(
|
||||
args.goal, "" if args.classifier == "default" else args.classifier
|
||||
)
|
||||
|
||||
if args.goal == "component":
|
||||
if args.classifier == "default":
|
||||
model_class_name = "component"
|
||||
|
@ -88,33 +81,6 @@ def main(args):
|
|||
else:
|
||||
model = model_class(args.lemmatization)
|
||||
model.train()
|
||||
else:
|
||||
model = model_class.load(model_file_name)
|
||||
|
||||
if args.classify:
|
||||
for bug in bugzilla.get_bugs():
|
||||
print(
|
||||
f'https://bugzilla.mozilla.org/show_bug.cgi?id={ bug["id"] } - { bug["summary"]} '
|
||||
)
|
||||
|
||||
if model.calculate_importance:
|
||||
probas, importance = model.classify(
|
||||
bug, probabilities=True, importances=True
|
||||
)
|
||||
|
||||
feature_names = model.get_human_readable_feature_names()
|
||||
|
||||
model.print_feature_importances(
|
||||
importance["importances"], feature_names, class_probabilities=probas
|
||||
)
|
||||
else:
|
||||
probas = model.classify(bug, probabilities=True, importances=False)
|
||||
|
||||
if np.argmax(probas) == 1:
|
||||
print(f"Positive! {probas}")
|
||||
else:
|
||||
print(f"Negative! {probas}")
|
||||
input()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
|
||||
from bugbug import bugzilla
|
||||
from bugbug.models import get_model_class
|
||||
|
||||
MODELS_WITH_TYPE = ("component",)
|
||||
|
||||
|
||||
def classify_bugs(model_name, classifier):
|
||||
if classifier != "default":
|
||||
assert (
|
||||
model_name in MODELS_WITH_TYPE
|
||||
), f"{classifier} is not a valid classifier type for {model_name}"
|
||||
|
||||
model_file_name = f"{model_name}{classifier}model"
|
||||
model_name = f"{model_name}_{classifier}"
|
||||
else:
|
||||
model_file_name = f"{model_name}model"
|
||||
|
||||
assert os.path.exists(
|
||||
model_file_name
|
||||
), f"{model_file_name} does not exist. Train the model with trainer.py first."
|
||||
|
||||
model_class = get_model_class(model_name)
|
||||
model = model_class.load(model_file_name)
|
||||
|
||||
for bug in bugzilla.get_bugs():
|
||||
print(
|
||||
f'https://bugzilla.mozilla.org/show_bug.cgi?id={bug["id"]} - {bug["summary"]} '
|
||||
)
|
||||
|
||||
if model.calculate_importance:
|
||||
probas, importance = model.classify(
|
||||
bug, probabilities=True, importances=True
|
||||
)
|
||||
|
||||
feature_names = model.get_human_readable_feature_names()
|
||||
|
||||
model.print_feature_importances(
|
||||
importance["importances"], feature_names, class_probabilities=probas
|
||||
)
|
||||
else:
|
||||
probas = model.classify(bug, probabilities=True, importances=False)
|
||||
|
||||
if np.argmax(probas) == 1:
|
||||
print(f"Positive! {probas}")
|
||||
else:
|
||||
print(f"Negative! {probas}")
|
||||
input()
|
||||
|
||||
|
||||
def main():
|
||||
description = "Perform evaluation on bugs using the specified model"
|
||||
parser = argparse.ArgumentParser(description=description)
|
||||
|
||||
parser.add_argument("model", help="Which model to use for evaluation")
|
||||
parser.add_argument(
|
||||
"--classifier",
|
||||
help="Type of the classifier. Only used for component classification.",
|
||||
choices=["default", "nn"],
|
||||
default="default",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
classify_bugs(args.model, args.classifier)
|
1
setup.py
1
setup.py
|
@ -49,6 +49,7 @@ setup(
|
|||
"bugbug-check = scripts.check:main",
|
||||
"bugbug-microannotate-generate = scripts.microannotate_generator:main",
|
||||
"bugbug-classify-commit = scripts.commit_classifier:main",
|
||||
"bugbug-classify-bug = scripts.bug_classifier:main",
|
||||
"bugbug-regressor-finder = scripts.regressor_finder:main",
|
||||
]
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче