Skip to content

Commit

Permalink
Create abae_model.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 7, 2024
1 parent 37afd61 commit 300025a
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions ai/abae/abae_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

class ABAEModel:
def __init__(self):
self.model = RandomForestClassifier()

def train(self, data):
X, y = data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
self.model.fit(X_train, y_train)

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

def evaluate(self, data):
X, y = data
y_pred = self.model.predict(X)
return accuracy_score(y, y_pred)

# Load dataset
df = pd.read_csv(" dataset.csv")

# Split dataset into features and target
X = df.drop("target", axis=1)
y = df["target"]

# Train model
model = ABAEModel()
model.train((X, y))

# Evaluate model
accuracy = model.evaluate((X, y))
print(f"Model accuracy: {accuracy:.3f}")

0 comments on commit 300025a

Please sign in to comment.