-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre_process.py
29 lines (22 loc) · 841 Bytes
/
pre_process.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
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
import joblib
# Load the dataset
data = pd.read_csv('health care diabetes.csv')
# Fill missing values with mean
data.fillna(data.mean(), inplace=True)
# Split the data into features and target
X = data.drop('Outcome', axis=1) # Features
y = data['Outcome'] # Target
# Split into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
# Train the RandomForest model
model = RandomForestClassifier()
model.fit(X_train, y_train)
# Evaluate the model
y_pred = model.predict(X_test)
print('Accuracy:', accuracy_score(y_test, y_pred))
# Save the model
joblib.dump(model, 'model/diabetes_model.pkl')