Skip to content

Commit

Permalink
Create ai_oracle.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Jun 19, 2024
1 parent 55ca528 commit 37c2fbd
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions network/blockchain/contracts/ai_oracle/ai_oracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

class AIOracle:
def __init__(self, data, target):
self.data = data
self.target = target
self.model = RandomForestClassifier(n_estimators=100)

def train(self):
X_train, X_test, y_train, y_test = train_test_split(self.data, self.target, test_size=0.2, random_state=42)
self.model.fit(X_train, y_train)
y_pred = self.model.predict(X_test)
print("Accuracy:", accuracy_score(y_test, y_pred))

def predict(self, input_data):
return self.model.predict(input_data)

def update(self, new_data, new_target):
self.data = np.concatenate((self.data, new_data))
self.target = np.concatenate((self.target, new_target))
self.train()

0 comments on commit 37c2fbd

Please sign in to comment.