Skip to content

Commit 4c6b23c

Browse files
Update ml-code-optimiser.py
1 parent 0c658dc commit 4c6b23c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/backend/neploy-build-python/ml-code-optimiser.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# comment # This code first reads the Python smart contract script from a file. Then, it uses the model to predict the suggested improvements for the smart contract code. Finally, it prints the suggested improvements
1+
# This code first reads the Python smart contract script from a file. Then, it uses the model to predict the suggested improvements for the smart contract code. Finally, it prints the suggested improvements
22

33
import numpy as np
44
import pandas as pd
@@ -45,10 +45,14 @@
4545
# Print the improvement suggestions
4646
if prediction == "optimize":
4747
print("The code needs to be optimized.")
48-
print("Suggested improvements:")
49-
for suggestion in model.predict_proba(new_code_vectorized)[0]:
50-
print(f"* {suggestion}")
48+
49+
# Get the top 3 suggestions
50+
top_3_suggestions = model.predict_proba(new_code_vectorized).argsort()[-3:][::-1]
51+
52+
# Print the suggestions
53+
for index in top_3_suggestions:
54+
snippet, probability = model.predict_proba(new_code_vectorized)[0][index]
55+
print(f"{index + 1}: {snippet} ({probability * 100:.2f}%)")
5156
else:
5257
print("The code is fine.")
5358

54-

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy