-
Notifications
You must be signed in to change notification settings - Fork 27
/
main_code.py
48 lines (36 loc) · 1.45 KB
/
main_code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# This challenge is designed for Wat.AI core member hiring process ( project name : Pitch.AI)
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, classification_report
def load_data(filepath):
# Load the dataset from the file and return it as a DataFrame
# TODO: Implement this function
pass
def preprocess_data(df):
# Perform preprocessing like scaling features
# TODO: Implement this function
pass
def train_model(X_train, y_train):
# Train a RandomForestClassifier on the provided data
# TODO: Implement this function
pass
def evaluate_model(model, X_test, y_test):
# Evaluate the trained model and return the accuracy and classification report
# TODO: Implement this function
pass
if __name__ == "__main__":
data_path = "data/spambase.csv"
# Load and preprocess the data
df = load_data(data_path)
df = preprocess_data(df)
# Split data into features and target
X = df.drop("target", axis=1)
y = df["target"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Train and evaluate the model
model = train_model(X_train, y_train)
accuracy, report = evaluate_model(model, X_test, y_test)
print(f"Model Accuracy: {accuracy:.2f}")
print(f"Classification Report:\n{report}")