<?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: Bharanidharan</title>
    <description>The latest articles on DEV Community by Bharanidharan (@bharanidharan_fcaccd5d553).</description>
    <link>https://dev.to/bharanidharan_fcaccd5d553</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3081745%2F70de585e-edb7-4d31-ae43-7a24a6e38a06.png</url>
      <title>DEV Community: Bharanidharan</title>
      <link>https://dev.to/bharanidharan_fcaccd5d553</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bharanidharan_fcaccd5d553"/>
    <language>en</language>
    <item>
      <title>🧠 Dockerize and Share Your ML Model: Logistic Regression with Iris Dataset</title>
      <dc:creator>Bharanidharan</dc:creator>
      <pubDate>Tue, 29 Apr 2025 05:48:01 +0000</pubDate>
      <link>https://dev.to/bharanidharan_fcaccd5d553/dockerize-and-share-your-ml-model-logistic-regression-with-iris-dataset-3adh</link>
      <guid>https://dev.to/bharanidharan_fcaccd5d553/dockerize-and-share-your-ml-model-logistic-regression-with-iris-dataset-3adh</guid>
      <description>&lt;p&gt;📦 Project Structure&lt;br&gt;
Here’s what our folder looks like:&lt;/p&gt;

&lt;p&gt;ml-docker-project/&lt;br&gt;
├── Dockerfile&lt;br&gt;
├── model.py&lt;br&gt;
└── Iris.csv&lt;br&gt;
🐳 Dockerfile Breakdown&lt;br&gt;
Here’s the Dockerfile we’re using:&lt;/p&gt;

&lt;h1&gt;
  
  
  Use the official Python image as a base
&lt;/h1&gt;

&lt;p&gt;FROM python:3.12-slim&lt;/p&gt;

&lt;h1&gt;
  
  
  Set working directory inside the container
&lt;/h1&gt;

&lt;p&gt;WORKDIR /app&lt;/p&gt;

&lt;h1&gt;
  
  
  Copy all files from the local machine to the container
&lt;/h1&gt;

&lt;p&gt;COPY . .&lt;/p&gt;

&lt;h1&gt;
  
  
  Install required Python packages
&lt;/h1&gt;

&lt;p&gt;RUN pip install --no-cache-dir pandas scikit-learn matplotlib&lt;/p&gt;

&lt;h1&gt;
  
  
  Command to run your Python script
&lt;/h1&gt;

&lt;p&gt;CMD ["python", "model.py"]&lt;/p&gt;

&lt;p&gt;This will:&lt;/p&gt;

&lt;p&gt;Use a slim Python base image&lt;br&gt;
Copy your local files&lt;br&gt;
Install all dependencies&lt;br&gt;
Run model.py on container start&lt;br&gt;
🧪 What model.py Does&lt;/p&gt;

&lt;p&gt;The script:&lt;/p&gt;

&lt;p&gt;from pandas import read_csv&lt;br&gt;
from matplotlib import pyplot&lt;br&gt;
from sklearn.linear_model import LogisticRegression&lt;br&gt;
from sklearn.model_selection import train_test_split&lt;br&gt;
import joblib&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 1: Load dataset
&lt;/h1&gt;

&lt;p&gt;filename = "Iris.csv"&lt;br&gt;
data = read_csv(filename)&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 2: Display data shape and preview
&lt;/h1&gt;

&lt;p&gt;print("Shape of the dataset:", data.shape)&lt;br&gt;
print("First 20 rows:\n", data.head(20))&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 3: Plot and save histograms silently
&lt;/h1&gt;

&lt;p&gt;data.hist()&lt;br&gt;
pyplot.savefig("histograms.png")&lt;br&gt;
pyplot.close()  # Close the plot so it doesn't show up in prompt&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 4: Plot and save density plots silently
&lt;/h1&gt;

&lt;p&gt;data.plot(kind='density', subplots=True, layout=(3,3), sharex=False)&lt;br&gt;
pyplot.savefig("density_plots.png")&lt;br&gt;
pyplot.close()&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 5: Convert to NumPy array and extract features/labels
&lt;/h1&gt;

&lt;p&gt;array = data.values&lt;br&gt;
X = array[:, 1:5]  # Features: Sepal/Petal measurements&lt;br&gt;
Y = array[:, 5]    # Target: Species&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 6: Split data into training (67%) and testing (33%)
&lt;/h1&gt;

&lt;p&gt;test_size = 0.33&lt;br&gt;
seed = 7&lt;br&gt;
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=test_size, random_state=seed)&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 7: Create and train logistic regression model
&lt;/h1&gt;

&lt;p&gt;model = LogisticRegression(max_iter=200)&lt;br&gt;
model.fit(X_train, Y_train)&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 8: Evaluate and display accuracy
&lt;/h1&gt;

&lt;p&gt;result = model.score(X_test, Y_test)&lt;br&gt;
print("Accuracy: {:.2f}%".format(result * 100))&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 9: Save the trained model to a file
&lt;/h1&gt;

&lt;p&gt;joblib.dump(model, "logistic_model.pkl")&lt;br&gt;
Visualizes the data (and saves plots)&lt;/p&gt;

&lt;p&gt;Trains a Logistic Regression model&lt;/p&gt;

&lt;p&gt;Evaluates it&lt;/p&gt;

&lt;p&gt;Saves the model as logistic_model.pkl&lt;/p&gt;

&lt;p&gt;It’s a full training pipeline, ready to be reproduced in any environment that runs Docker. 💪&lt;/p&gt;

&lt;p&gt;🔨 Step-by-Step: Build, Tag, and Push to DockerHub&lt;/p&gt;

&lt;p&gt;1️⃣ Build the Docker Image&lt;br&gt;
From your project directory:&lt;br&gt;
docker build -t viratpk18/24mcr078:latest .&lt;/p&gt;

&lt;p&gt;2️⃣ Log in to DockerHub&lt;br&gt;
docker login&lt;/p&gt;

&lt;p&gt;3️⃣ Push the Image&lt;br&gt;
docker push viratpk18/24mcr078:latest&lt;/p&gt;

&lt;p&gt;4️⃣ Then create the Dockerfile&lt;br&gt;
Image description&lt;/p&gt;

&lt;p&gt;📚 Resources&lt;/p&gt;

&lt;p&gt;🐳 Docker for ML Projects&lt;br&gt;
&lt;a href="https://docs.docker.com/language/python/" rel="noopener noreferrer"&gt;https://docs.docker.com/language/python/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🤖 scikit-learn Docs&lt;br&gt;
&lt;a href="https://scikit-learn.org/stable/" rel="noopener noreferrer"&gt;https://scikit-learn.org/stable/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📊 matplotlib Gallery&lt;br&gt;
&lt;a href="https://matplotlib.org/stable/gallery/index.html" rel="noopener noreferrer"&gt;https://matplotlib.org/stable/gallery/index.html&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>💯Step-by-Step Git Commands Execution:</title>
      <dc:creator>Bharanidharan</dc:creator>
      <pubDate>Thu, 24 Apr 2025 02:07:18 +0000</pubDate>
      <link>https://dev.to/bharanidharan_fcaccd5d553/step-by-step-git-commands-execution-3g4o</link>
      <guid>https://dev.to/bharanidharan_fcaccd5d553/step-by-step-git-commands-execution-3g4o</guid>
      <description>&lt;p&gt;&lt;strong&gt;Initialize a Git repository:&lt;/strong&gt;&lt;br&gt;
    &lt;em&gt;git init&lt;/em&gt;&lt;br&gt;
Creates a new Git repository in the folder 24MCR010.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Add a file to staging area:&lt;/strong&gt;&lt;br&gt;
    &lt;em&gt;git add 24MCR010.txt&lt;/em&gt;&lt;br&gt;
Adds 24MCR010.txt to the staging area.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Commit the file:&lt;/strong&gt;&lt;br&gt;
    &lt;em&gt;git commit -m "Added Personal Data"&lt;/em&gt;&lt;br&gt;
Creates a commit with the message "Added Personal Data".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check Git status:&lt;/strong&gt;&lt;br&gt;
     &lt;em&gt;git status&lt;/em&gt;&lt;br&gt;
Shows that 24MCR010.txt has been modified but not staged.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;View commit log:&lt;/strong&gt;&lt;br&gt;
     &lt;em&gt;git log&lt;/em&gt;&lt;br&gt;
Displays the commit history (one commit at this point).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Add remote GitHub repository:&lt;/strong&gt;&lt;br&gt;
    &lt;em&gt;git remote add origin &lt;a href="https://github.com/bharani195/24MCR010.git" rel="noopener noreferrer"&gt;https://github.com/bharani195/24MCR010.git&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Links the local repository to a remote GitHub repo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check current branch:&lt;/strong&gt;&lt;br&gt;
     &lt;em&gt;git branch&lt;/em&gt;&lt;br&gt;
Shows the current branch is master.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rename branch from master to main:&lt;/strong&gt;&lt;br&gt;
     &lt;em&gt;git branch -M main&lt;/em&gt;&lt;br&gt;
Renames the current branch to main.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Set Git global config for email and username:&lt;/strong&gt;&lt;br&gt;
    &lt;em&gt;git config --global user.email "&lt;a href="mailto:bharanidharan911.2k@gmail.com"&gt;bharanidharan911.2k@gmail.com&lt;/a&gt;"&lt;/em&gt;&lt;br&gt;
        &lt;em&gt;git config --global user.name "Bharanidharan911010"&lt;/em&gt;&lt;br&gt;
Sets your global Git identity.&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%2Fjvdbdrpqrnbuu832s9l3.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%2Fjvdbdrpqrnbuu832s9l3.png" alt="Image description" width="800" height="421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Push code to remote repo for the first time:&lt;/strong&gt;&lt;br&gt;
     &lt;em&gt;git push -u origin main&lt;/em&gt;&lt;br&gt;
Pushes the main branch to GitHub and sets upstream tracking.&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%2Fyga21xkjhfl8dqkqai5r.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%2Fyga21xkjhfl8dqkqai5r.png" alt="Image description" width="800" height="402"&gt;&lt;/a&gt;&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%2Fjey3fyxqfbxs4c03d6tn.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%2Fjey3fyxqfbxs4c03d6tn.png" alt="Image description" width="800" height="417"&gt;&lt;/a&gt;&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%2F1fe2weug2eaus02tnblk.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%2F1fe2weug2eaus02tnblk.png" alt="Image description" width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then , Again We will Modify or add new file means we need to follow the same steps, like&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
git commit -m “message”
git push origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
    </item>
  </channel>
</rss>
