<?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: / GUPTA KANAK JAIPRAKASH KOUSHALYA 20242554004</title>
    <description>The latest articles on DEV Community by / GUPTA KANAK JAIPRAKASH KOUSHALYA 20242554004 (@_guptakanakjaiprakash).</description>
    <link>https://dev.to/_guptakanakjaiprakash</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%2F4274880%2F48eec178-f7ea-482d-8eb4-9500c0eaf444.png</url>
      <title>DEV Community: / GUPTA KANAK JAIPRAKASH KOUSHALYA 20242554004</title>
      <link>https://dev.to/_guptakanakjaiprakash</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_guptakanakjaiprakash"/>
    <language>en</language>
    <item>
      <title>Artificial Neural Network</title>
      <dc:creator>/ GUPTA KANAK JAIPRAKASH KOUSHALYA 20242554004</dc:creator>
      <pubDate>Mon, 30 Nov 2026 18:35:41 +0000</pubDate>
      <link>https://dev.to/_guptakanakjaiprakash/artificial-neural-network-ld2</link>
      <guid>https://dev.to/_guptakanakjaiprakash/artificial-neural-network-ld2</guid>
      <description>&lt;h1&gt;
  
  
  Artificial Neural Network (ANN) – A Beginner's Guide with Python
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Category:&lt;/strong&gt; Machine Learning | Deep Learning | Data Science&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;Artificial Intelligence allows computers to perform tasks that normally require human-like intelligence.&lt;/p&gt;

&lt;p&gt;Artificial Neural Networks (ANNs) are machine learning models inspired, in a simplified way, by networks of connected neurons. They learn patterns from examples and are widely used in modern Artificial Intelligence applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. What is an Artificial Neural Network?
&lt;/h2&gt;

&lt;p&gt;An Artificial Neural Network is a computational model made up of connected processing units called neurons.&lt;/p&gt;

&lt;p&gt;These neurons are arranged in layers. Each connection has a weight, and neurons use activation functions to transform their inputs.&lt;/p&gt;

&lt;p&gt;ANNs can learn relationships and patterns from data to perform prediction and classification tasks.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Architecture and Working of ANN
&lt;/h2&gt;

&lt;p&gt;A basic Artificial Neural Network contains three main types of layers.&lt;/p&gt;

&lt;h3&gt;
  
  
  A. Input Layer
&lt;/h3&gt;

&lt;p&gt;Receives the input data and passes it to the network.&lt;/p&gt;

&lt;h3&gt;
  
  
  B. Hidden Layer
&lt;/h3&gt;

&lt;p&gt;Processes the information using weights, biases and activation functions.&lt;/p&gt;

&lt;h3&gt;
  
  
  C. Output Layer
&lt;/h3&gt;

&lt;p&gt;Produces the final prediction or classification result.&lt;/p&gt;

&lt;h3&gt;
  
  
  ANN Architecture
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Input Layer → Hidden Layer(s) → Output Layer&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Mathematical Formula
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;a = f(w₁x₁ + w₂x₂ + … + b)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;a:&lt;/strong&gt; Output of the neuron.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;x:&lt;/strong&gt; Input values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;w:&lt;/strong&gt; Weights.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;b:&lt;/strong&gt; Bias.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;f:&lt;/strong&gt; Activation function.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How Does ANN Work?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Input data enters the network.&lt;/li&gt;
&lt;li&gt;Neurons calculate weighted sums.&lt;/li&gt;
&lt;li&gt;Activation functions transform the values.&lt;/li&gt;
&lt;li&gt;The output layer generates a prediction.&lt;/li&gt;
&lt;li&gt;The model compares the prediction with the correct answer.&lt;/li&gt;
&lt;li&gt;Backpropagation and optimisation update the weights during training.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  4. Common Activation Functions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  A. ReLU
&lt;/h3&gt;

&lt;p&gt;ReLU is commonly used in hidden layers. It returns zero for negative inputs and the input itself for positive inputs.&lt;/p&gt;

&lt;h3&gt;
  
  
  B. Sigmoid
&lt;/h3&gt;

&lt;p&gt;Sigmoid converts values into a range between 0 and 1.&lt;/p&gt;

&lt;h3&gt;
  
  
  C. Softmax
&lt;/h3&gt;

&lt;p&gt;Softmax converts output scores into class probabilities for multi-class classification.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Python Implementation
&lt;/h2&gt;

&lt;p&gt;We can implement an Artificial Neural Network using Python and Scikit-learn.&lt;/p&gt;

&lt;p&gt;In this example, we use the Iris flower dataset to classify flowers into three categories.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Install Required Libraries
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Python Program
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;datasets&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_iris&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model_selection&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;train_test_split&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;neural_network&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;MLPClassifier&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;accuracy_score&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;preprocessing&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;StandardScaler&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;make_pipeline&lt;/span&gt;

&lt;span class="c1"&gt;# Load Iris dataset&lt;/span&gt;
&lt;span class="n"&gt;iris&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load_iris&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Split the dataset&lt;/span&gt;
&lt;span class="nc"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;train_test_split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;iris&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;iris&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;test_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;stratify&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;iris&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Create ANN model&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;make_pipeline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;StandardScaler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;MLPClassifier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;hidden_layer_sizes&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;max_iter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Train the model&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Make predictions&lt;/span&gt;
&lt;span class="n"&gt;predictions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Calculate accuracy&lt;/span&gt;
&lt;span class="n"&gt;accuracy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;accuracy_score&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;predictions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Test accuracy:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;accuracy&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"%"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Expected Output
&lt;/h2&gt;

&lt;p&gt;The program displays the test accuracy as a percentage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Test accuracy: (model-generated percentage) %
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The model trains using the training dataset and predicts flower categories from the test dataset.&lt;/p&gt;

&lt;p&gt;The accuracy indicates the percentage of test samples classified correctly. The exact value may vary depending on software versions and training settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Real-Life Applications of ANN
&lt;/h2&gt;

&lt;p&gt;Artificial Neural Networks are used in:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Image recognition.&lt;/li&gt;
&lt;li&gt;Speech recognition.&lt;/li&gt;
&lt;li&gt;Recommendation systems.&lt;/li&gt;
&lt;li&gt;Demand forecasting.&lt;/li&gt;
&lt;li&gt;Text classification.&lt;/li&gt;
&lt;li&gt;Pattern detection in scientific data.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  8. Advantages of ANN
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Can learn complex non-linear patterns.&lt;/li&gt;
&lt;li&gt;Supports different types of input data.&lt;/li&gt;
&lt;li&gt;Can be used for classification and regression.&lt;/li&gt;
&lt;li&gt;Useful in many Artificial Intelligence applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  9. Limitations of ANN
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;May require substantial training data.&lt;/li&gt;
&lt;li&gt;Can require significant computing resources.&lt;/li&gt;
&lt;li&gt;Can be difficult to interpret.&lt;/li&gt;
&lt;li&gt;Requires careful model tuning.&lt;/li&gt;
&lt;li&gt;May overfit without proper validation and regularisation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  10. Conclusion
&lt;/h2&gt;

&lt;p&gt;Artificial Neural Networks are an important foundation of modern Deep Learning.&lt;/p&gt;

&lt;p&gt;They learn patterns from data using interconnected neurons, weights, biases and activation functions.&lt;/p&gt;

&lt;p&gt;Understanding ANN architecture and training provides a strong foundation for studying advanced deep learning models such as CNNs and RNNs.&lt;/p&gt;

&lt;h2&gt;
  
  
  11. References and Further Reading
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://scikit-learn.org/stable/" rel="noopener noreferrer"&gt;Scikit-learn Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.tensorflow.org/learn" rel="noopener noreferrer"&gt;TensorFlow Learning Resources&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/" rel="noopener noreferrer"&gt;GeeksforGeeks – Computer Science&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;




</description>
      <category>ai</category>
      <category>deeplearning</category>
      <category>machinelearning</category>
      <category>python</category>
    </item>
    <item>
      <title>RNN: A Beginner's Guide to Sequential Data with Python</title>
      <dc:creator>/ GUPTA KANAK JAIPRAKASH KOUSHALYA 20242554004</dc:creator>
      <pubDate>Mon, 30 Nov 2026 18:33:58 +0000</pubDate>
      <link>https://dev.to/_guptakanakjaiprakash/rnn-a-beginners-guide-to-sequential-data-with-python-3ppj</link>
      <guid>https://dev.to/_guptakanakjaiprakash/rnn-a-beginners-guide-to-sequential-data-with-python-3ppj</guid>
      <description>&lt;p&gt;Category: Machine Learning | Deep Learning | Data Science&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Some data has a specific order, such as words in a sentence, daily temperatures or stock measurements over time.&lt;/p&gt;

&lt;p&gt;In these situations, earlier information can help us understand later information.&lt;/p&gt;

&lt;p&gt;A Recurrent Neural Network (RNN) is a type of deep learning model designed to process sequential data.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is an RNN?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A Recurrent Neural Network is an artificial neural network that processes a sequence one step at a time and maintains a hidden state.&lt;/p&gt;

&lt;p&gt;This hidden state carries information from earlier steps and helps the model understand the current input using previous context.&lt;/p&gt;

&lt;p&gt;Example: An RNN can process the words in a sentence one by one to understand its meaning.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How Does an RNN Work?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An RNN processes information step by step.&lt;/p&gt;

&lt;p&gt;At each time step:&lt;/p&gt;

&lt;p&gt;The network receives the current input.&lt;/p&gt;

&lt;p&gt;It uses the previous hidden state.&lt;/p&gt;

&lt;p&gt;It calculates an updated hidden state.&lt;/p&gt;

&lt;p&gt;It may produce an output.&lt;/p&gt;

&lt;p&gt;The process continues for the next input.&lt;/p&gt;

&lt;p&gt;The same network weights are reused across different time steps.&lt;/p&gt;

&lt;p&gt;Training commonly uses a technique called Backpropagation Through Time (BPTT).&lt;/p&gt;

&lt;p&gt;RNN Architecture&lt;/p&gt;

&lt;p&gt;Input at Time 1 → Hidden State → Input at Time 2 → Updated Hidden State&lt;/p&gt;

&lt;p&gt;Mathematical Formula&lt;/p&gt;

&lt;p&gt;hₜ = f(Wₓxₜ + Wₕhₜ₋₁ + b)&lt;/p&gt;

&lt;p&gt;Where:&lt;/p&gt;

&lt;p&gt;hₜ: Current hidden state.&lt;/p&gt;

&lt;p&gt;xₜ: Current input.&lt;/p&gt;

&lt;p&gt;hₜ₋₁: Previous hidden state.&lt;/p&gt;

&lt;p&gt;Wₓ: Input weight.&lt;/p&gt;

&lt;p&gt;Wₕ: Recurrent weight.&lt;/p&gt;

&lt;p&gt;b: Bias.&lt;/p&gt;

&lt;p&gt;f: Activation function.&lt;/p&gt;

&lt;p&gt;The current hidden state depends on both the current input and the previous hidden state.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Types and Variants of RNN&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Many-to-One&lt;/p&gt;

&lt;p&gt;Used to classify an entire sequence into one output.&lt;/p&gt;

&lt;p&gt;Example: Sentiment analysis of a customer review.&lt;/p&gt;

&lt;p&gt;B. One-to-Many&lt;/p&gt;

&lt;p&gt;Takes one input and generates a sequence of outputs.&lt;/p&gt;

&lt;p&gt;Example: Generating a sequence from an image or initial input.&lt;/p&gt;

&lt;p&gt;C. Many-to-Many&lt;/p&gt;

&lt;p&gt;Maps an input sequence to an output sequence.&lt;/p&gt;

&lt;p&gt;Example: Sequence labelling and language translation.&lt;/p&gt;

&lt;p&gt;D. LSTM (Long Short-Term Memory)&lt;/p&gt;

&lt;p&gt;LSTM is a special type of RNN that uses gates to help preserve useful information over longer sequences.&lt;/p&gt;

&lt;p&gt;E. GRU (Gated Recurrent Unit)&lt;/p&gt;

&lt;p&gt;GRU is another gated RNN variant designed to help manage information and long-term dependencies.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Python Implementation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We can implement a simple RNN using TensorFlow and Keras.&lt;/p&gt;

&lt;p&gt;In this example, we create a small model that learns to calculate the sum of five numbers in a sequence.&lt;/p&gt;

&lt;p&gt;Step 1: Install Required Libraries&lt;/p&gt;

&lt;p&gt;pip install numpy tensorflow&lt;/p&gt;

&lt;p&gt;Step 2: Python Program&lt;/p&gt;

&lt;p&gt;import numpy as np&lt;br&gt;
import tensorflow as tf&lt;br&gt;
from tensorflow.keras import Sequential&lt;br&gt;
from tensorflow.keras.layers import Input, SimpleRNN, Dense&lt;/p&gt;

&lt;h1&gt;
  
  
  Create sample data
&lt;/h1&gt;

&lt;p&gt;X = np.random.rand(100, 5, 1).astype("float32")&lt;/p&gt;

&lt;h1&gt;
  
  
  Target: sum of five values
&lt;/h1&gt;

&lt;p&gt;y = X.sum(axis=1)&lt;/p&gt;

&lt;h1&gt;
  
  
  Create RNN model
&lt;/h1&gt;

&lt;p&gt;model = Sequential([&lt;br&gt;
    Input(shape=(5, 1)),&lt;br&gt;
    SimpleRNN(16, activation="tanh"),&lt;br&gt;
    Dense(1)&lt;br&gt;
])&lt;/p&gt;

&lt;h1&gt;
  
  
  Compile the model
&lt;/h1&gt;

&lt;p&gt;model.compile(&lt;br&gt;
    optimizer="adam",&lt;br&gt;
    loss="mse"&lt;br&gt;
)&lt;/p&gt;

&lt;h1&gt;
  
  
  Train the model
&lt;/h1&gt;

&lt;p&gt;model.fit(&lt;br&gt;
    X, y,&lt;br&gt;
    epochs=10,&lt;br&gt;
    batch_size=8,&lt;br&gt;
    verbose=0&lt;br&gt;
)&lt;/p&gt;

&lt;h1&gt;
  
  
  Make a prediction
&lt;/h1&gt;

&lt;p&gt;sample = X[:1]&lt;/p&gt;

&lt;p&gt;prediction = model.predict(sample, verbose=0)&lt;/p&gt;

&lt;p&gt;print("Predicted sum:", prediction[0][0])&lt;br&gt;
print("Actual sum:", y[0][0])&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Expected Output&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The program prints two values:&lt;/p&gt;

&lt;p&gt;Predicted sum: (model-generated value)&lt;br&gt;
Actual sum: (actual sum of the five input values)&lt;/p&gt;

&lt;p&gt;Output Explanation:&lt;/p&gt;

&lt;p&gt;Predicted sum represents the value estimated by the trained RNN.&lt;/p&gt;

&lt;p&gt;Actual sum represents the correct sum of the five input values.&lt;/p&gt;

&lt;p&gt;The exact predicted value varies because the sample data and initial model weights are random.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Real-Life Applications of RNN&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;RNNs are used in various applications:&lt;/p&gt;

&lt;p&gt;Language modelling and text processing.&lt;/p&gt;

&lt;p&gt;Speech recognition.&lt;/p&gt;

&lt;p&gt;Time-series forecasting.&lt;/p&gt;

&lt;p&gt;Sequence labelling.&lt;/p&gt;

&lt;p&gt;Sensor-data analysis.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Advantages of RNN&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Processes ordered and sequential data.&lt;/p&gt;

&lt;p&gt;Reuses weights across time steps.&lt;/p&gt;

&lt;p&gt;Uses previous information as context.&lt;/p&gt;

&lt;p&gt;Suitable for many sequence-learning tasks.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Limitations of RNN&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Basic RNNs can struggle with long-term dependencies.&lt;/p&gt;

&lt;p&gt;Training can be slower because sequence steps are processed in order.&lt;/p&gt;

&lt;p&gt;May experience vanishing or exploding gradients.&lt;/p&gt;

&lt;p&gt;LSTM and GRU architectures help address some of these limitations.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Recurrent Neural Networks introduced an effective way for neural networks to process sequential data and use information from earlier steps.&lt;/p&gt;

&lt;p&gt;They are important in understanding sequence modelling, speech recognition, language processing and time-series analysis.&lt;/p&gt;

&lt;p&gt;Learning RNNs provides a foundation for studying advanced deep learning architectures such as LSTM and GRU.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;References and Further Reading&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;TensorFlow Learning Resources&lt;/p&gt;

&lt;p&gt;Scikit-learn Documentation&lt;/p&gt;

&lt;p&gt;GeeksforGeeks – Computer Science&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>deeplearning</category>
      <category>machinelearning</category>
      <category>python</category>
    </item>
    <item>
      <title>CNN: A Beginner's Guide to Image Recognition with Python</title>
      <dc:creator>/ GUPTA KANAK JAIPRAKASH KOUSHALYA 20242554004</dc:creator>
      <pubDate>Mon, 30 Nov 2026 18:29:38 +0000</pubDate>
      <link>https://dev.to/_guptakanakjaiprakash/cnn-a-beginners-guide-to-image-recognition-with-python-3bhm</link>
      <guid>https://dev.to/_guptakanakjaiprakash/cnn-a-beginners-guide-to-image-recognition-with-python-3bhm</guid>
      <description>&lt;p&gt;Category: Machine Learning | Deep Learning | Computer Vision&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Images contain different patterns such as edges, shapes, textures and objects. Deep Learning provides techniques that allow computers to learn these visual features automatically.&lt;/p&gt;

&lt;p&gt;A Convolutional Neural Network (CNN) is a deep learning model designed especially for image processing and computer vision.&lt;/p&gt;

&lt;p&gt;CNNs are widely used in image recognition and classification applications.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is a CNN?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A Convolutional Neural Network is a type of Artificial Neural Network that is especially effective for image-like grid data.&lt;/p&gt;

&lt;p&gt;It uses filters to detect local patterns and builds increasingly complex features through multiple layers.&lt;/p&gt;

&lt;p&gt;For example, a CNN can learn to identify edges, shapes and objects in an image.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How Does a CNN Work?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A CNN processes an image through different layers.&lt;/p&gt;

&lt;p&gt;Input Image: The original image is given to the model.&lt;/p&gt;

&lt;p&gt;Convolution: Filters move across the image to detect patterns.&lt;/p&gt;

&lt;p&gt;ReLU Activation: Adds non-linearity to the model.&lt;/p&gt;

&lt;p&gt;Pooling: Reduces the spatial dimensions of feature maps.&lt;/p&gt;

&lt;p&gt;Dense Layer: Uses learned features to make a prediction.&lt;/p&gt;

&lt;p&gt;CNN Architecture&lt;/p&gt;

&lt;p&gt;Input Image → Convolution + ReLU → Pooling → Dense Classifier → Prediction&lt;/p&gt;

&lt;p&gt;Convolution Formula&lt;/p&gt;

&lt;p&gt;Feature Map = Input Image * Filter&lt;/p&gt;

&lt;p&gt;The convolution operation applies a filter to local image regions and calculates responses to identify important features.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Main CNN Layers&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Convolution Layer&lt;/p&gt;

&lt;p&gt;Detects patterns such as edges, shapes and textures using filters.&lt;/p&gt;

&lt;p&gt;B. ReLU Activation Layer&lt;/p&gt;

&lt;p&gt;Introduces non-linearity and helps the network learn complex patterns.&lt;/p&gt;

&lt;p&gt;C. Pooling Layer&lt;/p&gt;

&lt;p&gt;Reduces the dimensions of feature maps while retaining important information.&lt;/p&gt;

&lt;p&gt;D. Flatten Layer&lt;/p&gt;

&lt;p&gt;Converts feature maps into a one-dimensional vector.&lt;/p&gt;

&lt;p&gt;E. Dense Layer&lt;/p&gt;

&lt;p&gt;Uses the extracted features to produce the final prediction.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Python Implementation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We can implement a simple CNN using TensorFlow and Keras.&lt;/p&gt;

&lt;p&gt;In this example, we use the CIFAR-10 dataset, which contains 32 × 32 colour images belonging to 10 classes.&lt;/p&gt;

&lt;p&gt;Step 1: Install TensorFlow&lt;/p&gt;

&lt;p&gt;pip install tensorflow&lt;/p&gt;

&lt;p&gt;Step 2: Python Program&lt;/p&gt;

&lt;p&gt;import tensorflow as tf&lt;br&gt;
from tensorflow.keras import layers, models&lt;/p&gt;

&lt;h1&gt;
  
  
  Load CIFAR-10 dataset
&lt;/h1&gt;

&lt;p&gt;(x_train, y_train), (x_test, y_test) = tf.keras.datasets.cifar10.load_data()&lt;/p&gt;

&lt;h1&gt;
  
  
  Normalize pixel values from 0-255 to 0-1
&lt;/h1&gt;

&lt;p&gt;x_train = x_train.astype("float32") / 255.0&lt;br&gt;
x_test = x_test.astype("float32") / 255.0&lt;/p&gt;

&lt;h1&gt;
  
  
  Create CNN model
&lt;/h1&gt;

&lt;p&gt;model = models.Sequential([&lt;br&gt;
    layers.Input(shape=(32, 32, 3)),&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;layers.Conv2D(32, (3, 3), activation="relu"),
layers.MaxPooling2D((2, 2)),

layers.Conv2D(64, (3, 3), activation="relu"),
layers.MaxPooling2D((2, 2)),

layers.Flatten(),
layers.Dense(64, activation="relu"),
layers.Dense(10, activation="softmax")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;])&lt;/p&gt;

&lt;h1&gt;
  
  
  Compile the model
&lt;/h1&gt;

&lt;p&gt;model.compile(&lt;br&gt;
    optimizer="adam",&lt;br&gt;
    loss="sparse_categorical_crossentropy",&lt;br&gt;
    metrics=["accuracy"]&lt;br&gt;
)&lt;/p&gt;

&lt;h1&gt;
  
  
  Display model architecture
&lt;/h1&gt;

&lt;p&gt;model.summary()&lt;/p&gt;

&lt;h1&gt;
  
  
  Optional training
&lt;/h1&gt;

&lt;h1&gt;
  
  
  model.fit(
&lt;/h1&gt;

&lt;h1&gt;
  
  
  x_train, y_train,
&lt;/h1&gt;

&lt;h1&gt;
  
  
  epochs=5,
&lt;/h1&gt;

&lt;h1&gt;
  
  
  validation_data=(x_test, y_test)
&lt;/h1&gt;

&lt;h1&gt;
  
  
  )
&lt;/h1&gt;

&lt;p&gt;Step 3: Expected Output&lt;/p&gt;

&lt;p&gt;When you execute the program, model.summary() displays:&lt;/p&gt;

&lt;p&gt;Layer names and types.&lt;/p&gt;

&lt;p&gt;Output shapes.&lt;/p&gt;

&lt;p&gt;Number of parameters.&lt;/p&gt;

&lt;p&gt;Total trainable parameters.&lt;/p&gt;

&lt;p&gt;If you uncomment and execute the training section, the model trains for five epochs. Accuracy depends on training settings and runtime.&lt;/p&gt;

&lt;p&gt;Note: Five epochs are used here for learning purposes and are not intended to produce state-of-the-art accuracy.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Real-Life Applications of CNN&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;CNNs are used in many fields:&lt;/p&gt;

&lt;p&gt;Face and object recognition.&lt;/p&gt;

&lt;p&gt;Medical image analysis.&lt;/p&gt;

&lt;p&gt;Quality inspection in manufacturing.&lt;/p&gt;

&lt;p&gt;Traffic-sign recognition.&lt;/p&gt;

&lt;p&gt;Image classification in mobile applications.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Advantages of CNN&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Automatically learns image features.&lt;/p&gt;

&lt;p&gt;Captures spatial patterns.&lt;/p&gt;

&lt;p&gt;Reduces the need for manually designed image features.&lt;/p&gt;

&lt;p&gt;Can achieve strong performance on visual tasks.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Limitations of CNN&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Training may require substantial data.&lt;/p&gt;

&lt;p&gt;Can require high computing power.&lt;/p&gt;

&lt;p&gt;Models can be difficult to interpret.&lt;/p&gt;

&lt;p&gt;Performance depends on data quality.&lt;/p&gt;

&lt;p&gt;Can be sensitive to changes in image conditions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Convolutional Neural Networks are among the most important deep learning architectures used in computer vision.&lt;/p&gt;

&lt;p&gt;Their convolution and pooling operations help models learn useful visual features from raw images.&lt;/p&gt;

&lt;p&gt;Understanding CNN architecture provides a strong foundation for learning advanced image recognition and deep learning techniques.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;References and Further Reading&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;TensorFlow Learning Resources&lt;/p&gt;

&lt;p&gt;Scikit-learn Documentation&lt;/p&gt;

&lt;p&gt;GeeksforGeeks – Computer Science&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>deeplearning</category>
      <category>machinelearning</category>
      <category>python</category>
    </item>
    <item>
      <title>Dynamic Programming: A Beginner's Guide with Python</title>
      <dc:creator>/ GUPTA KANAK JAIPRAKASH KOUSHALYA 20242554004</dc:creator>
      <pubDate>Mon, 30 Nov 2026 18:26:57 +0000</pubDate>
      <link>https://dev.to/_guptakanakjaiprakash/dynamic-programming-a-beginners-guide-with-python-270k</link>
      <guid>https://dev.to/_guptakanakjaiprakash/dynamic-programming-a-beginners-guide-with-python-270k</guid>
      <description>&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Many computer science problems involve repeating the same calculations. Solving every repeated subproblem from scratch can waste time.&lt;/p&gt;

&lt;p&gt;Dynamic Programming (DP) is a problem-solving technique that stores results of smaller subproblems so they can be reused.&lt;/p&gt;

&lt;p&gt;It helps programmers solve complex problems more efficiently.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is Dynamic Programming?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Dynamic Programming is an algorithmic technique used to solve problems by breaking them into smaller, overlapping subproblems.&lt;/p&gt;

&lt;p&gt;It stores the answers to those subproblems and combines them to solve the original problem.&lt;/p&gt;

&lt;p&gt;Example: The Fibonacci sequence is a common example of Dynamic Programming.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How Does Dynamic Programming Work?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A DP solution usually identifies:&lt;/p&gt;

&lt;p&gt;State: Represents a subproblem.&lt;/p&gt;

&lt;p&gt;Recurrence Relation: Defines how smaller answers are combined.&lt;/p&gt;

&lt;p&gt;Base Cases: The starting values.&lt;/p&gt;

&lt;p&gt;Storage: Saves calculated results for reuse.&lt;/p&gt;

&lt;p&gt;Instead of recalculating a value, the algorithm retrieves its previously stored answer.&lt;/p&gt;

&lt;p&gt;Fibonacci Formula&lt;/p&gt;

&lt;p&gt;F(n) = F(n − 1) + F(n − 2)&lt;/p&gt;

&lt;p&gt;Base cases:&lt;/p&gt;

&lt;p&gt;F(0) = 0&lt;/p&gt;

&lt;p&gt;F(1) = 1&lt;/p&gt;

&lt;p&gt;Every later value is calculated from the two previous values.&lt;/p&gt;

&lt;p&gt;Working Steps&lt;/p&gt;

&lt;p&gt;Identify the original problem.&lt;/p&gt;

&lt;p&gt;Break it into smaller subproblems.&lt;/p&gt;

&lt;p&gt;Calculate their answers.&lt;/p&gt;

&lt;p&gt;Store the results.&lt;/p&gt;

&lt;p&gt;Reuse the stored results to find the final answer.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Two Main Approaches&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Memoization (Top-Down Approach)&lt;/p&gt;

&lt;p&gt;Memoization uses recursion to solve smaller subproblems and stores their results.&lt;/p&gt;

&lt;p&gt;When the same subproblem appears again, the stored result is reused instead of calculating it again.&lt;/p&gt;

&lt;p&gt;B. Tabulation (Bottom-Up Approach)&lt;/p&gt;

&lt;p&gt;Tabulation fills a table starting from the smallest cases and gradually works towards the final answer.&lt;/p&gt;

&lt;p&gt;It generally uses iteration instead of recursion.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Python Implementation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Fibonacci sequence is a classic introductory example of Dynamic Programming.&lt;/p&gt;

&lt;p&gt;Each number is the sum of the previous two numbers. A DP list stores earlier values so they are not recalculated.&lt;/p&gt;

&lt;p&gt;Python Program&lt;/p&gt;

&lt;p&gt;def fibonacci_dp(n):&lt;br&gt;
    if n &amp;lt; 0:&lt;br&gt;
        raise ValueError("n must be non-negative")&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if n == 0:
    return 0

dp = [0] * (n + 1)
dp[1] = 1

for i in range(2, n + 1):
    dp[i] = dp[i - 1] + dp[i - 2]

return dp[n]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;print("10th Fibonacci number:", fibonacci_dp(10))&lt;br&gt;
print("15th Fibonacci number:", fibonacci_dp(15))&lt;/p&gt;

&lt;p&gt;Sample Output&lt;/p&gt;

&lt;p&gt;10th Fibonacci number: 55&lt;br&gt;
15th Fibonacci number: 610&lt;/p&gt;

&lt;p&gt;Output Explanation&lt;/p&gt;

&lt;p&gt;The program calculates Fibonacci numbers using Dynamic Programming.&lt;/p&gt;

&lt;p&gt;The 10th Fibonacci number is 55.&lt;/p&gt;

&lt;p&gt;The 15th Fibonacci number is 610.&lt;/p&gt;

&lt;p&gt;The program stores previously calculated values in a list and reuses them to avoid repeated calculations.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Real-Life and Computer Science Applications&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Dynamic Programming is used in:&lt;/p&gt;

&lt;p&gt;Shortest-path and route-planning problems.&lt;/p&gt;

&lt;p&gt;Resource allocation.&lt;/p&gt;

&lt;p&gt;Text comparison and edit distance.&lt;/p&gt;

&lt;p&gt;Scheduling problems.&lt;/p&gt;

&lt;p&gt;Knapsack optimisation.&lt;/p&gt;

&lt;p&gt;Sequence analysis.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Advantages of Dynamic Programming&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Avoids repeated calculations.&lt;/p&gt;

&lt;p&gt;Can greatly improve efficiency.&lt;/p&gt;

&lt;p&gt;Provides a structured way to solve overlapping subproblems.&lt;/p&gt;

&lt;p&gt;Useful for optimisation problems.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Limitations of Dynamic Programming&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Some solutions require significant memory.&lt;/p&gt;

&lt;p&gt;Identifying the correct state and recurrence can be difficult.&lt;/p&gt;

&lt;p&gt;Not every problem has overlapping subproblems and optimal substructure.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Dynamic Programming is an important technique for designing efficient algorithms.&lt;/p&gt;

&lt;p&gt;By saving and reusing subproblem results, it can turn an impractical repeated calculation into a manageable solution.&lt;/p&gt;

&lt;p&gt;Learning Dynamic Programming helps students develop problem-solving skills and understand how complex computational problems can be solved efficiently.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;References and Further Reading&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;GeeksforGeeks – Computer Science&lt;/p&gt;

&lt;p&gt;Scikit-learn Documentation&lt;/p&gt;

&lt;p&gt;TensorFlow Learning Resources&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>python</category>
    </item>
    <item>
      <title>Logistic Regression: A Beginner's Guide with Python</title>
      <dc:creator>/ GUPTA KANAK JAIPRAKASH KOUSHALYA 20242554004</dc:creator>
      <pubDate>Mon, 30 Nov 2026 18:24:23 +0000</pubDate>
      <link>https://dev.to/_guptakanakjaiprakash/logistic-regression-a-beginners-guide-with-python-4icf</link>
      <guid>https://dev.to/_guptakanakjaiprakash/logistic-regression-a-beginners-guide-with-python-4icf</guid>
      <description>&lt;h1&gt;
  
  
  Logistic Regression – A Beginner's Guide with Python
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Category:&lt;/strong&gt; Machine Learning | Data Science&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;Machine Learning can be used not only to predict numerical values but also to classify information into categories.&lt;/p&gt;

&lt;p&gt;For example, a bank may want to predict whether a transaction is fraudulent, or a doctor may study whether a test result indicates a possible condition.&lt;/p&gt;

&lt;p&gt;Logistic Regression is a widely used supervised learning algorithm for classification.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. What is Logistic Regression?
&lt;/h2&gt;

&lt;p&gt;Logistic Regression is a supervised machine learning algorithm mainly used to predict the probability of a categorical outcome.&lt;/p&gt;

&lt;p&gt;Although its name contains the word regression, it is commonly used for classification tasks such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Yes or No&lt;/li&gt;
&lt;li&gt;0 or 1&lt;/li&gt;
&lt;li&gt;Spam or Not Spam&lt;/li&gt;
&lt;li&gt;Pass or Fail&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. How Does Logistic Regression Work?
&lt;/h2&gt;

&lt;p&gt;The algorithm calculates a weighted combination of input features and passes the result through the &lt;strong&gt;Sigmoid Function&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The sigmoid function converts the result into a probability between 0 and 1.&lt;/p&gt;

&lt;p&gt;A threshold, often 0.5, can then be used to assign a class.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mathematical Formula
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;p = 1 / (1 + e⁻ᶻ)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;p:&lt;/strong&gt; Predicted probability&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;e:&lt;/strong&gt; Mathematical constant&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;z:&lt;/strong&gt; Weighted sum of input features&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Working Steps
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Provide input features.&lt;/li&gt;
&lt;li&gt;Calculate the weighted sum.&lt;/li&gt;
&lt;li&gt;Apply the sigmoid function.&lt;/li&gt;
&lt;li&gt;Calculate the probability.&lt;/li&gt;
&lt;li&gt;Assign the final class using a threshold.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; If the predicted probability of an email being spam is 0.90, the model may classify it as Spam using a threshold of 0.5.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Types of Logistic Regression
&lt;/h2&gt;

&lt;h3&gt;
  
  
  A. Binary Logistic Regression
&lt;/h3&gt;

&lt;p&gt;Used when there are only two possible classes.&lt;/p&gt;

&lt;p&gt;Example: Pass or Fail.&lt;/p&gt;

&lt;h3&gt;
  
  
  B. Multinomial Logistic Regression
&lt;/h3&gt;

&lt;p&gt;Used when there are three or more unordered classes.&lt;/p&gt;

&lt;p&gt;Example: Classifying fruits as Apple, Banana or Orange.&lt;/p&gt;

&lt;h3&gt;
  
  
  C. Ordinal Logistic Regression
&lt;/h3&gt;

&lt;p&gt;Used when categories have a meaningful order.&lt;/p&gt;

&lt;p&gt;Example: Low, Medium and High satisfaction.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Python Implementation
&lt;/h2&gt;

&lt;p&gt;We can implement Logistic Regression using Python and the Scikit-learn library.&lt;/p&gt;

&lt;p&gt;In this example, we use the Iris dataset and select two classes for binary classification.&lt;/p&gt;

&lt;h3&gt;
  
  
  Python Program
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;datasets&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_iris&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;linear_model&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;LogisticRegression&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model_selection&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;train_test_split&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;accuracy_score&lt;/span&gt;

&lt;span class="c1"&gt;# Load the Iris dataset&lt;/span&gt;
&lt;span class="n"&gt;iris&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load_iris&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Keep only the first two classes&lt;/span&gt;
&lt;span class="no"&gt;X&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;iris&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;iris&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;iris&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;iris&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# Split the dataset&lt;/span&gt;
&lt;span class="nc"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;train_test_split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;test_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stratify&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Create the model&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LogisticRegression&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_iter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Train the model&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Make predictions&lt;/span&gt;
&lt;span class="n"&gt;predictions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Display accuracy&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Accuracy:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nf"&gt;accuracy_score&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;predictions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"%"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Predicted class for first test row:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sample Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Accuracy: 100.0 %
Predicted class for first test row: 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output Explanation
&lt;/h3&gt;

&lt;p&gt;The model achieved 100% accuracy on this particular test split.&lt;/p&gt;

&lt;p&gt;The predicted class for the first test row is 1, representing the second selected Iris class.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Real-Life Applications
&lt;/h2&gt;

&lt;p&gt;Logistic Regression is used in various fields:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Email spam detection.&lt;/li&gt;
&lt;li&gt;Customer churn prediction.&lt;/li&gt;
&lt;li&gt;Disease-risk classification.&lt;/li&gt;
&lt;li&gt;Loan default assessment.&lt;/li&gt;
&lt;li&gt;Fraud detection.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  7. Advantages of Logistic Regression
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Relatively simple to understand and train.&lt;/li&gt;
&lt;li&gt;Provides probability-based predictions.&lt;/li&gt;
&lt;li&gt;Computationally efficient for many datasets.&lt;/li&gt;
&lt;li&gt;Useful as a baseline classification model.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. Limitations of Logistic Regression
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Creates a linear decision boundary unless features are transformed.&lt;/li&gt;
&lt;li&gt;Performance can be affected by multicollinearity.&lt;/li&gt;
&lt;li&gt;May struggle with complex patterns.&lt;/li&gt;
&lt;li&gt;Performance can be affected by unbalanced classes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  9. Conclusion
&lt;/h2&gt;

&lt;p&gt;Logistic Regression is a foundational classification algorithm in Machine Learning.&lt;/p&gt;

&lt;p&gt;It is useful when we need a clear and efficient model that estimates class probabilities.&lt;/p&gt;

&lt;p&gt;Learning Logistic Regression helps students understand classification, probability and the working of supervised machine learning algorithms.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. References and Further Reading
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://scikit-learn.org/stable/" rel="noopener noreferrer"&gt;Scikit-learn Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.tensorflow.org/learn" rel="noopener noreferrer"&gt;TensorFlow Learning Resources&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;




</description>
      <category>machinelearning</category>
      <category>python</category>
    </item>
    <item>
      <title># Linear Regression – A Beginner's Guide with Python **Category:** Machine Learning | Data Science</title>
      <dc:creator>/ GUPTA KANAK JAIPRAKASH KOUSHALYA 20242554004</dc:creator>
      <pubDate>Mon, 30 Nov 2026 18:20:35 +0000</pubDate>
      <link>https://dev.to/_guptakanakjaiprakash/-linear-regression-a-beginners-guide-with-python-category-machine-learning-data-53ee</link>
      <guid>https://dev.to/_guptakanakjaiprakash/-linear-regression-a-beginners-guide-with-python-category-machine-learning-data-53ee</guid>
      <description>&lt;h1&gt;
  
  
  Linear Regression – A Beginner's Guide with Python
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Category:&lt;/strong&gt; Machine Learning | Data Science&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;In Data Science, predicting future outcomes using existing data is an important task. Businesses may want to estimate sales, banks may need to understand financial trends, and educators may want to study student performance.&lt;/p&gt;

&lt;p&gt;Machine Learning provides techniques that help us make these predictions.&lt;/p&gt;

&lt;p&gt;One of the simplest and most widely used techniques is &lt;strong&gt;Linear Regression&lt;/strong&gt;. It is a useful starting point for understanding machine learning because its predictions and relationships are relatively easy to interpret.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. What is Linear Regression?
&lt;/h2&gt;

&lt;p&gt;Linear Regression is a supervised machine learning algorithm used to predict a continuous numerical value.&lt;/p&gt;

&lt;p&gt;It identifies the relationship between one or more input variables and an output variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A model can study the relationship between the number of hours a student studies and the marks they receive. It can then estimate the marks of another student based on their study hours.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. How Does Linear Regression Work?
&lt;/h2&gt;

&lt;p&gt;Linear Regression finds a line that best represents the relationship between the data points.&lt;/p&gt;

&lt;p&gt;It compares actual values with predicted values and tries to minimise the differences, commonly using the &lt;strong&gt;Least Squares Method&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mathematical Equation
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Y = mX + C&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Y:&lt;/strong&gt; Predicted output&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;X:&lt;/strong&gt; Input variable&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;m:&lt;/strong&gt; Slope of the line&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;C:&lt;/strong&gt; Intercept (predicted value when X is zero)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Basic Working Steps
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Collect the input data.&lt;/li&gt;
&lt;li&gt;Identify the relationship between variables.&lt;/li&gt;
&lt;li&gt;Fit the best possible line through the data points.&lt;/li&gt;
&lt;li&gt;Train the model.&lt;/li&gt;
&lt;li&gt;Use the trained model to make predictions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; As study hours increase, student marks may also increase. Linear Regression learns this general trend.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Types of Linear Regression
&lt;/h2&gt;

&lt;h3&gt;
  
  
  A. Simple Linear Regression
&lt;/h3&gt;

&lt;p&gt;Uses one independent variable to predict an output.&lt;/p&gt;

&lt;p&gt;Example: Predicting student marks using study hours.&lt;/p&gt;

&lt;h3&gt;
  
  
  B. Multiple Linear Regression
&lt;/h3&gt;

&lt;p&gt;Uses two or more independent variables to predict an output.&lt;/p&gt;

&lt;p&gt;Example: Predicting house prices using area, age and number of rooms.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Python Implementation
&lt;/h2&gt;

&lt;p&gt;We can implement Simple Linear Regression in Python using the Scikit-learn library.&lt;/p&gt;

&lt;p&gt;In this example, we will predict student marks based on study hours.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Install Required Libraries
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install numpy scikit-learn matplotlib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Python Program
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;matplotlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;linear_model&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;LinearRegression&lt;/span&gt;

&lt;span class="c1"&gt;# Input: hours studied&lt;/span&gt;
&lt;span class="no"&gt;X&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reshape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Output: marks obtained&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;55&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;65&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;70&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Create and train the model&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LinearRegression&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Predict marks for 7 study hours&lt;/span&gt;
&lt;span class="n"&gt;prediction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Predicted marks:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prediction&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Draw the data and regression line&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scatter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"blue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Actual marks"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;plot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"red"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Regression line"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;xlabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Study Hours"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ylabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Marks"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Linear Regression: Study Hours vs Marks"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;legend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Sample Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Predicted marks: 77.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The model predicts that a student who studies for 7 hours may score approximately 77 marks based on the sample dataset.&lt;/p&gt;

&lt;p&gt;The graph displays:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Blue points: Actual student marks.&lt;/li&gt;
&lt;li&gt;Red line: Predicted regression line.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. Real-Life Applications
&lt;/h2&gt;

&lt;p&gt;Linear Regression is used in many fields:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Predicting house prices using area and location.&lt;/li&gt;
&lt;li&gt;Estimating student marks based on study hours.&lt;/li&gt;
&lt;li&gt;Forecasting sales and business revenue.&lt;/li&gt;
&lt;li&gt;Estimating product demand.&lt;/li&gt;
&lt;li&gt;Analysing trends and relationships between variables.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  7. Advantages of Linear Regression
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Easy to understand and implement.&lt;/li&gt;
&lt;li&gt;Requires relatively low computational power.&lt;/li&gt;
&lt;li&gt;Helps explain relationships between variables.&lt;/li&gt;
&lt;li&gt;Provides an interpretable baseline for prediction tasks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. Limitations of Linear Regression
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Works best when relationships are approximately linear.&lt;/li&gt;
&lt;li&gt;Can be affected by outliers.&lt;/li&gt;
&lt;li&gt;May not capture complex patterns.&lt;/li&gt;
&lt;li&gt;Its assumptions should be checked before relying on predictions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  9. Conclusion
&lt;/h2&gt;

&lt;p&gt;Linear Regression is an important starting point for understanding Machine Learning.&lt;/p&gt;

&lt;p&gt;Although it is a basic algorithm, it is useful in many industries for prediction and data analysis.&lt;/p&gt;

&lt;p&gt;Learning Linear Regression helps students understand how a machine learning model identifies patterns in data and uses them to estimate numerical outcomes.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. References and Further Reading
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://scikit-learn.org/stable/modules/linear_model.html" rel="noopener noreferrer"&gt;Scikit-learn – Linear Models&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/machine-learning/crash-course/linear-regression" rel="noopener noreferrer"&gt;Google – Linear Regression&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.statlearning.com/" rel="noopener noreferrer"&gt;An Introduction to Statistical Learning&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;




</description>
      <category>beginners</category>
      <category>datascience</category>
      <category>machinelearning</category>
      <category>python</category>
    </item>
    <item>
      <title>Linear Regression: A Beginner's Guide with Python</title>
      <dc:creator>/ GUPTA KANAK JAIPRAKASH KOUSHALYA 20242554004</dc:creator>
      <pubDate>Mon, 30 Nov 2026 18:11:50 +0000</pubDate>
      <link>https://dev.to/_guptakanakjaiprakash/linear-regression-a-beginners-guide-with-python-5e79</link>
      <guid>https://dev.to/_guptakanakjaiprakash/linear-regression-a-beginners-guide-with-python-5e79</guid>
      <description>&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;In Data Science, predicting future outcomes using existing data is an important task. Businesses may want to estimate sales, banks may need to understand financial trends, and educators may want to study student performance.&lt;/p&gt;

&lt;p&gt;Machine Learning provides techniques that help us make these predictions.&lt;/p&gt;

&lt;p&gt;One of the simplest and most widely used techniques is &lt;strong&gt;Linear Regression&lt;/strong&gt;. It is a useful starting point for understanding machine learning because its predictions and relationships are relatively easy to interpret.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. What is Linear Regression?
&lt;/h2&gt;

&lt;p&gt;Linear Regression is a supervised machine learning algorithm used to predict a continuous numerical value.&lt;/p&gt;

&lt;p&gt;It identifies the relationship between one or more input variables and an output variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A model can study the relationship between the number of hours a student studies and the marks they receive. It can then estimate the marks of another student based on their study hours.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. How Does Linear Regression Work?
&lt;/h2&gt;

&lt;p&gt;Linear Regression finds a line that best represents the relationship between the data points.&lt;/p&gt;

&lt;p&gt;It compares actual values with predicted values and tries to minimise the differences, commonly using the &lt;strong&gt;Least Squares Method&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mathematical Equation
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Y = mX + C&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Y:&lt;/strong&gt; Predicted output&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;X:&lt;/strong&gt; Input variable&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;m:&lt;/strong&gt; Slope of the line&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;C:&lt;/strong&gt; Intercept (predicted value when X is zero)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Basic Working Steps
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Collect the input data.&lt;/li&gt;
&lt;li&gt;Identify the relationship between variables.&lt;/li&gt;
&lt;li&gt;Fit the best possible line through the data points.&lt;/li&gt;
&lt;li&gt;Train the model.&lt;/li&gt;
&lt;li&gt;Use the trained model to make predictions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; As study hours increase, student marks may also increase. Linear Regression learns this general trend.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Types of Linear Regression
&lt;/h2&gt;

&lt;h3&gt;
  
  
  A. Simple Linear Regression
&lt;/h3&gt;

&lt;p&gt;Uses one independent variable to predict an output.&lt;/p&gt;

&lt;p&gt;Example: Predicting student marks using study hours.&lt;/p&gt;

&lt;h3&gt;
  
  
  B. Multiple Linear Regression
&lt;/h3&gt;

&lt;p&gt;Uses two or more independent variables to predict an output.&lt;/p&gt;

&lt;p&gt;Example: Predicting house prices using area, age and number of rooms.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Python Implementation
&lt;/h2&gt;

&lt;p&gt;We can implement Simple Linear Regression in Python using the Scikit-learn library.&lt;/p&gt;

&lt;p&gt;In this example, we will predict student marks based on study hours.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Install Required Libraries
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install numpy scikit-learn matplotlib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Python Program
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;matplotlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;linear_model&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;LinearRegression&lt;/span&gt;

&lt;span class="c1"&gt;# Input: hours studied&lt;/span&gt;
&lt;span class="no"&gt;X&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reshape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Output: marks obtained&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;55&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;65&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;70&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Create and train the model&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LinearRegression&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Predict marks for 7 study hours&lt;/span&gt;
&lt;span class="n"&gt;prediction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Predicted marks:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prediction&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Draw the data and regression line&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scatter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"blue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Actual marks"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;plot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"red"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Regression line"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;xlabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Study Hours"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ylabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Marks"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Linear Regression: Study Hours vs Marks"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;legend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Sample Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Predicted marks: 77.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The model predicts that a student who studies for 7 hours may score approximately 77 marks based on the sample dataset.&lt;/p&gt;

&lt;p&gt;The graph displays:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Blue points: Actual student marks.&lt;/li&gt;
&lt;li&gt;Red line: Predicted regression line.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. Real-Life Applications
&lt;/h2&gt;

&lt;p&gt;Linear Regression is used in many fields:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Predicting house prices using area and location.&lt;/li&gt;
&lt;li&gt;Estimating student marks based on study hours.&lt;/li&gt;
&lt;li&gt;Forecasting sales and business revenue.&lt;/li&gt;
&lt;li&gt;Estimating product demand.&lt;/li&gt;
&lt;li&gt;Analysing trends and relationships between variables.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  7. Advantages of Linear Regression
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Easy to understand and implement.&lt;/li&gt;
&lt;li&gt;Requires relatively low computational power.&lt;/li&gt;
&lt;li&gt;Helps explain relationships between variables.&lt;/li&gt;
&lt;li&gt;Provides an interpretable baseline for prediction tasks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. Limitations of Linear Regression
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Works best when relationships are approximately linear.&lt;/li&gt;
&lt;li&gt;Can be affected by outliers.&lt;/li&gt;
&lt;li&gt;May not capture complex patterns.&lt;/li&gt;
&lt;li&gt;Its assumptions should be checked before relying on predictions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  9. Conclusion
&lt;/h2&gt;

&lt;p&gt;Linear Regression is an important starting point for understanding Machine Learning.&lt;/p&gt;

&lt;p&gt;Although it is a basic algorithm, it is useful in many industries for prediction and data analysis.&lt;/p&gt;

&lt;p&gt;Learning Linear Regression helps students understand how a machine learning model identifies patterns in data and uses them to estimate numerical outcomes.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. References and Further Reading
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://scikit-learn.org/stable/modules/linear_model.html" rel="noopener noreferrer"&gt;Scikit-learn – Linear Models&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/machine-learning/crash-course/linear-regression" rel="noopener noreferrer"&gt;Google – Linear Regression&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.statlearning.com/" rel="noopener noreferrer"&gt;An Introduction to Statistical Learning&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;em&gt;Created for learning and educational purposes.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Topic: Linear Regression in Machine Learning&lt;/strong&gt;&lt;/p&gt;

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