Write down similarity predictions Parameters: - test -- path to the testset file specifying pairs of source code file to analyze similarity - probabilities -- numpy array with probabilities of similarities - filename -- filename to write
(test, probabilities, filename)
| 169 | return np.asarray(labels) |
| 170 | |
| 171 | def writePredictions(test, probabilities, filename): |
| 172 | """ |
| 173 | Write down similarity predictions |
| 174 | Parameters: |
| 175 | - test -- path to the testset file specifying pairs |
| 176 | of source code file to analyze similarity |
| 177 | - probabilities -- numpy array with probabilities of similarities |
| 178 | - filename -- filename to write predictions |
| 179 | """ |
| 180 | with open(test, newline='') as csvin,\ |
| 181 | open(filename, 'w', newline='') as csvout: |
| 182 | test_reader = csv.reader(csvin) |
| 183 | writer = csv.writer(csvout, lineterminator=os.linesep) |
| 184 | test_reader.__next__() #Skip csv header |
| 185 | writer.writerow(["pair-id", "file1", "file2", |
| 186 | "confidence", "prediction"]) |
| 187 | _i = 0 |
| 188 | for _num, _fn1, _fn2 in test_reader: |
| 189 | writer.writerow([_num, _fn1, _fn2, probabilities[_i][0], |
| 190 | "Similar" if probabilities[_i][0] >= 0.5 |
| 191 | else "Dissimilar"]) |
| 192 | _i += 1 |
| 193 | |
| 194 | def main(args): |
| 195 | """ |