-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiabetes.py
42 lines (32 loc) · 1.54 KB
/
diabetes.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
# Import necessary libraries
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, classification_report
from sklearn.preprocessing import StandardScaler
# Load the dataset (replace 'your_dataset.csv' with your actual dataset)
data = pd.read_csv('E:\2024\diabetes prediction system\diabetes data.csv')
# Explore the dataset and preprocess if necessary
# For simplicity, let's assume the dataset has columns like 'feature1', 'feature2', ..., 'target'
# 'target' is the column indicating whether the person has diabetes or not (1 for diabetes, 0 for no diabetes)
# Separate features and target variable
X = data.drop('target', axis=1)
y = data['target']
# Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Standardize the features (optional but can be beneficial for some models)
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
# Create a Random Forest Classifier (you can use other algorithms as well)
model = RandomForestClassifier(random_state=42)
# Train the model
model.fit(X_train, y_train)
# Make predictions on the test set
y_pred = model.predict(X_test)
# Evaluate the model
accuracy = accuracy_score(y_test, y_pred)
report = classification_report(y_test, y_pred)
print(f"Accuracy: {accuracy}")
print("Classification Report:\n", report)