Training the Machine Learning Model - Step-by-Step
1. Load the Data
We use pandas to read a CSV file that contains health data. The file has patient information like age,
glucose, blood pressure, and whether they had a disease. Code: data = pd.read_csv('[Link]')
2. Split Features (X) and Labels (y)
We separate the input values (X) and the target label (y):
- X includes all columns except 'disease'
- y includes only the 'disease' column
Code:
X = [Link]('disease', axis=1)
y = data['disease']
3. Create the Model
We create a RandomForestClassifier model. This is a machine learning model that uses multiple decision
trees to make predictions. Code:
model = RandomForestClassifier()
4. Train the Model
We train the model using our input (X) and output (y) data. This is where the model learns patterns from the
dataset. Code:
[Link](X, y)
5. Save the Model using Pickle
After training, we save the model to a file so it can be used later in our web app. We use the pickle library to
do this. Code:
[Link](model, open('[Link]', 'wb'))
Conclusion
This script trains a smart model on medical data. The model is saved and later used in the Flask web app to
Training the Machine Learning Model - Step-by-Step
predict diseases based on user input.