From c98cb727536b8c934b56e98b0a9424ef8430adbd Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sat, 20 Jul 2024 22:57:09 +0700 Subject: [PATCH] Create train.py --- ai-auditor-module/train.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 ai-auditor-module/train.py diff --git a/ai-auditor-module/train.py b/ai-auditor-module/train.py new file mode 100644 index 000000000..29d47f10b --- /dev/null +++ b/ai-auditor-module/train.py @@ -0,0 +1,26 @@ +# ai-auditor-module/train.py +import pandas as pd +from sklearn.ensemble import RandomForestClassifier +from sklearn.model_selection import train_test_split + +# Load dataset +dataset = pd.read_csv('smart_contract_data.csv') + +# Preprocess data +X = dataset.drop(['label'], axis=1) +y = dataset['label'] + +# Split data into training and testing sets +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) + +# Train the model +model = RandomForestClassifier(n_estimators=100, random_state=42) +model.fit(X_train, y_train) + +# Evaluate the model +accuracy = model.score(X_test, y_test) +print(f'Model accuracy: {accuracy:.3f}') + +# Save the model +import joblib +joblib.dump(model, 'ai_model.joblib')