Skip to content

Instantly share code, notes, and snippets.

@cassioiks
Last active October 20, 2017 12:26
Show Gist options
  • Save cassioiks/c95fa968d553b2ef6a516a814579d755 to your computer and use it in GitHub Desktop.
Save cassioiks/c95fa968d553b2ef6a516a814579d755 to your computer and use it in GitHub Desktop.
How to run the Code Defect ML model

What is this

This is a service built to indicate if some code is defect-prone or not. The service uses an SVM classifier. The model was tested and validaded against 2 different sets, achieving an accuracy of ~98%.

The features present in the dataset, and that have to be provided to the service, are the following:

Feature Description
loc numeric % McCabe's line count of code
v(g) numeric % McCabe "cyclomatic complexity"
ev(g) numeric % McCabe "essential complexity"
iv(g) numeric % McCabe "design complexity"
n numeric % Halstead total operators + operands
v numeric % Halstead "volume"
l numeric % Halstead "program length"
d numeric % Halstead "difficulty"
i numeric % Halstead "intelligence"
e numeric % Halstead "effort"
b numeric % Halstead
t numeric % Halstead's time estimator
lOCode numeric % Halstead's line count
lOComment numeric % Halstead's count of lines of comments
lOBlank numeric % Halstead's count of blank lines
lOCodeAndComment numeric
uniq_Op numeric % unique operators
uniq_Opnd numeric % unique operands
total_Op numeric % total operators
total_Opnd numeric % total operands
branchCount numeric % of the flow graph

How to

The service endpoint is https://code-defect-ml.herokuapp.com/predict

Method: POST

Sample JSON payloads:

[129,30,18,25,402,2583.36,0.02,46.42,55.65,119927.45,0.86,6662.64,111,1,14,1,34,52,260,142,58]
[20,2,1,2,47,212.61,0.22,4.59,46.28,976.67,0.07,54.26,11,1,4,1,7,16,26,21,3]

Sample service response:

{
    "prediction": [
        1
    ]
}

Obs: A prediction 1 indicates true for defect-prone code. A prediction 0 indicates false for defect-prone code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment