<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aagama AR</title>
    <description>The latest articles on DEV Community by Aagama AR (@aagama_ar).</description>
    <link>https://dev.to/aagama_ar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1793901%2Fa4eca322-d74a-4a2e-a3f9-8c4d91dacb8e.jpg</url>
      <title>DEV Community: Aagama AR</title>
      <link>https://dev.to/aagama_ar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aagama_ar"/>
    <language>en</language>
    <item>
      <title>Build a Diabetes Prediction Web App Using Machine Learning - A Beginner-Friendly Project Guide</title>
      <dc:creator>Aagama AR</dc:creator>
      <pubDate>Wed, 02 Jul 2025 19:35:39 +0000</pubDate>
      <link>https://dev.to/aagama_ar/build-a-diabetes-prediction-web-app-using-machine-learning-a-beginner-friendly-project-guide-3g10</link>
      <guid>https://dev.to/aagama_ar/build-a-diabetes-prediction-web-app-using-machine-learning-a-beginner-friendly-project-guide-3g10</guid>
      <description>&lt;p&gt;Hey, have you ever wondered how machine learning can be used to predict diseases? In this &lt;strong&gt;beginner-friendly&lt;/strong&gt; guide, I'll show you a step-by-step how to build a real ML model to predict diabetes using medical data - and then deploy it as a web app using Streamlit!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ivdo8sbamvcpdpf3o4h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ivdo8sbamvcpdpf3o4h.png" alt="Image description" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No prior experience with ML? No worries. I'll break down everything into simple terms. By the end, you'll not only understand the key concepts but will have built and deployed your own working project.&lt;/p&gt;

&lt;p&gt;🔗 GitHub Repo (Full Code):&lt;br&gt;
 👉 &lt;a href="https://github.com/aagamaar/DIABETIC_PREDICTION" rel="noopener noreferrer"&gt;diabetes-prediction&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🧠&lt;strong&gt;What You'll Learn :&lt;/strong&gt;&lt;br&gt;
 ✅ How to use a real-world dataset for training a model&lt;br&gt;
 ✅ What a classifier is and why we use it&lt;br&gt;
 ✅ What it means to "train" a model&lt;br&gt;
 ✅ How to save the model and use it to make predictions&lt;br&gt;
 ✅ How to build an interactive web app (with no HTML or JS!)&lt;br&gt;
 ✅ How to deploy your project online&lt;/p&gt;



&lt;p&gt;📊 &lt;strong&gt;The Dataset - Explained Simply&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We're using the PIMA Indians Diabetes Dataset from Kaggle. It contains medical records of women aged 21+, with features like:&lt;/p&gt;

&lt;p&gt;Pregnancies: Number of times pregnant&lt;/p&gt;

&lt;p&gt;Glucose: Blood sugar levels&lt;/p&gt;

&lt;p&gt;Blood Pressure&lt;/p&gt;

&lt;p&gt;Skin Thickness: Body fat measure&lt;/p&gt;

&lt;p&gt;Insulin: Insulin level in blood&lt;/p&gt;

&lt;p&gt;BMI: Body Mass Index&lt;/p&gt;

&lt;p&gt;Diabetes Pedigree Function: Family history of diabetes&lt;/p&gt;

&lt;p&gt;Age&lt;/p&gt;

&lt;p&gt;The last column is Outcome:&lt;br&gt;
0 = not diabetic&lt;br&gt;
1 = diabetic&lt;/p&gt;

&lt;p&gt;👉 Our goal: train a machine to predict this Outcome using the other inputs.&lt;/p&gt;

&lt;p&gt;📥 Get it here: &lt;a href="https://www.kaggle.com/datasets/uciml/pima-indians-diabetes-database?resource=download" rel="noopener noreferrer"&gt;PIMA Dataset on Kaggle&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;**&lt;br&gt;
🛠️ Step 1: Project Setup&lt;br&gt;
**&lt;br&gt;
Make a folder like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;diabetes-prediction/
│
├── diabetes.csv            # Your dataset
├── train_model.py          # Trains your model
├── trained_model.sav       # Output file (saved model)
└── diabetes_app.py         # Streamlit web app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Use a Virtual Environment&lt;br&gt;
This keeps your project clean and avoids dependency issues.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python -m venv venv
source venv/bin/activate      # Windows: venv\Scripts\activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Install Required Libraries&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install pandas numpy scikit-learn streamlit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or if you have a requirements.txt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install -r requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;🤖 Step 2: Train the Machine Learning Model&lt;/p&gt;

&lt;p&gt;Let's break this part down 👇&lt;/p&gt;

&lt;p&gt;💡 What is a Machine Learning Model?&lt;/p&gt;

&lt;p&gt;A model is a mathematical formula that learns patterns from data and then uses those patterns to make predictions. Just like how we learn from examples, the model "learns" from the dataset.&lt;/p&gt;

&lt;p&gt;We'll use a model called a Support Vector Machine (SVM). Don't worry about the name - just think of it as a smart classifier that tries to separate diabetic vs. non-diabetic patients.&lt;/p&gt;




&lt;p&gt;🧪 Inside train_model.py&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Load the data
df = pd.read_csv('diabetes.csv')

# Split into input (X) and output (Y)
X = df.drop('Outcome', axis=1)
Y = df['Outcome']

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We use 80% for training, 20% for testing - so we can see how well our model performs on unseen data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from sklearn.model_selection import train_test_split
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, stratify=Y, test_size=0.2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Train the model using a linear classifier (fast and accurate for this type of data):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from sklearn.svm import SVC
model = SVC(kernel='linear')
model.fit(X_train, Y_train)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the accuracy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from sklearn.metrics import accuracy_score
print("Training Accuracy:", accuracy_score(Y_train, model.predict(X_train)))
print("Test Accuracy:", accuracy_score(Y_test, model.predict(X_test)))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pickle
pickle.dump(model, open('trained_model.sav', 'wb'))
Run the script:
python train_model.py

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;🌐 &lt;strong&gt;Step 3: Build the Streamlit Web App&lt;/strong&gt;&lt;br&gt;
💡 What is Streamlit?&lt;/p&gt;

&lt;p&gt;Streamlit is like magic 🪄 - it turns Python scripts into beautiful web apps without writing any frontend code.&lt;/p&gt;



&lt;p&gt;Inside diabetes_app.py&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Load the saved model
model = pickle.load(open('trained_model.sav', 'rb'))


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a function to make predictions
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def predict(input_data):
    input_np = np.asarray(input_data).reshape(1, -1)
    result = model.predict(input_np)
    return 'Diabetic' if result[0] == 1 else 'Not Diabetic'


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Design the app UI using Streamlit
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import streamlit as st
st.title("🩺 Diabetes Prediction Web App")
preg = st.number_input("Pregnancies", 0)
glu = st.number_input("Glucose", 0)
bp = st.number_input("Blood Pressure", 0)
skin = st.number_input("Skin Thickness", 0)
insulin = st.number_input("Insulin", 0)
bmi = st.number_input("BMI", 0.0)
dpf = st.number_input("Diabetes Pedigree Function", 0.0)
age = st.number_input("Age", 0)
if st.button("Predict"):
    result = predict([preg, glu, bp, skin, insulin, bmi, dpf, age])
    st.success(f"The person is {result}")

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;▶️ Step 4: Run the App&lt;br&gt;
Run this in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;streamlit run diabetes_app.py

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🎉 You'll get an interactive web page where you can input values and see results instantly.&lt;/p&gt;




&lt;p&gt;🧠 &lt;strong&gt;Common Questions (for Beginners)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;❓ What's the difference between training and testing?&lt;br&gt;
Training = Teaching the model&lt;br&gt;
Testing = Checking if it learned well&lt;/p&gt;

&lt;p&gt;❓ What does "saving the model" mean?&lt;br&gt;
It's like saving a recipe so we don't have to re-cook from scratch each time.&lt;/p&gt;

&lt;p&gt;❓ Why use Streamlit?&lt;br&gt;
It's beginner-friendly and avoids the complexity of HTML/JS/CSS. Perfect for data projects!&lt;/p&gt;




&lt;p&gt;_☁️ &lt;strong&gt;Optional: Deploy on Streamlit Cloud&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Want to share your app with others?&lt;br&gt;
Push your code to GitHub&lt;br&gt;
Go to streamlit.io/cloud&lt;br&gt;
Click New App and select diabetes_app.py&lt;br&gt;
Done! 🌍 Your app is now live&lt;br&gt;
_&lt;/p&gt;




&lt;p&gt;💬 &lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;br&gt;
Building your first ML project doesn't have to be hard. This project covers the full cycle:&lt;/p&gt;

&lt;p&gt;✅ Load real data&lt;br&gt;
 ✅ Train a model&lt;br&gt;
 ✅ Save and reuse it&lt;br&gt;
 ✅ Build a web app&lt;br&gt;
 ✅ Share it with the world&lt;/p&gt;

&lt;p&gt;Give it a try, fork the repo, tweak the code - and most importantly, have fun learning! 😄&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>ai</category>
      <category>python</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
