-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |