Bijan Krishna Paul

VILL- DEBANDI, AMTA, HOWRAH PIN-711410 Phone-9836357266

Total Pageviews

Monday, August 17, 2026

HOW TO TRAIN A MODEL STEP BY STEP IN PYTHON

 

HOW TO TRAIN A MODEL STEP BY STEP IN PYTHON:

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

from sklearn.linear_model import LinearRegression

from sklearn.metrics import mean_squared_error, r2_score


data = {

'Hours': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],

'Scores': [10, 20, 30, 40, 50, 60, 70, 80, 85, 95]

}


df = pd.DataFrame(data)

print(df.head())


   Hours  Scores
0      1      10
1      2      20
2      3      30
3      4      40
4      5      50




plt.scatter(df['Hours'], df['Scores']) plt.xlabel('Hours Studied') plt.ylabel('Scores') plt.title('Hours vs Scores') plt.show()





X = df[['Hours']] # Independent variable y = df['Scores'] # Dependent variable #Now split into training and testing sets: X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)


model = LinearRegression() model.fit(X_train, y_train)

Parameters
fit_interceptTrue
copy_XTrue
tol1e-06
n_jobsNone
positiveFalse
Fitted attributes
NameTypeValue
coef_ndarray[float64](1,)[9.61]
feature_names_in_ndarray[object](1,)['Hours']
intercept_float641.509
n_features_in_int1
rank_int1
singular_ndarray[float64](1,)[7.62]
y_pred = model.predict(X_test)

print(y_pred)

[88.01724138 20.73275862]
print("Mean Squared Error:", mean_squared_error(y_test, y_pred))

print("R2 Score:", r2_score(y_test, y_pred))
Mean Squared Error: 4.820340368608807
R2 Score: 0.9954363641480627
y_pred = model.predict(X_test) print(y_pred)


[88.01724138 20.73275862]

print("Mean Squared Error:", mean_squared_error(y_test, y_pred)) print("R2 Score:", r2_score(y_test, y_pred))

Mean Squared Error: 4.820340368608807
R2 Score: 0.9954363641480627


plt.scatter(X, y, color='blue') plt.plot(X, model.predict(X), color='red') plt.xlabel('Hours Studied') plt.ylabel('Scores') plt.title('Linear Regression - Hours vs Scores') plt.show()




hours = np.array([[7.5]]) predicted_score = model.predict(hours) print(f"Predicted Score for 7.5 hours: {predicted_score[0]}")
Predicted Score for 7.5 hours: 73.59913793103448
Posted by bijan krishna paul at 12:55 PM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Search This Blog

WELCOME

BKP SIR
BKP SIRBlog Search Assistant
👋 Hello! I am BKP SIR.
I can search only the B.K. Paul Computer Science Blog for notes, syllabus, practicals, programs and other posts.
BKP SIR is searching...
🔎 Searches only bijankrishnapaulcs.blogspot.com

WEST BENGAL STATE UNIVERSITY COMPUTER SCIENCE NEP NEW SYLLABUS COMPUTER SCIENCE 2023 NEP

SEM 1SEM 2SEM 3
SEM 4SEM 5SEM 6

UNIVERSITY OF CALCUTTA

SEM 1 SEM 2 SEM 3
SEM 4 SEM 5 SEM 6

WEST BENGAL STATE UNIVERSITY CBCS SYLLABUS(2018-2022)

SEM 1SEM 2SEM 3
SEM 4SEM 5SEM 6

SCHOOL

CLASS-4CLASS-5CLASS-6
CLASS-7CLASS-8CLASS-9
CLASS10CLASS11 applicationCLASS12 application
CLASS11 scienceCLASS12 science

core subject

C C++ CORE JAVA SQL PYTHON
MS OFFICE HTML VISUAL BASIC advanced java 8085
PROLOG ASSEMBLY LANGUAGE JAVA SCRIPT SHELL PROGRAMMING R
DIGITAL ELECTRONICS COMPUTER ARCHITECTURE DATA STRUCTURE OPERATING SYSTEM GRAPH THEORY
DISCRETE MATHEMATICS NUMERICAL ALGORITHM AUTOMATA MICROPROCESSOR NETWORKING
GRAPHICS SOFTWARE ENGINEERING DATABSE ANALYSIS OF ALGORITHM IMAGE PROCESSING
ARTIFICIAL INTELLIGENCE BIG DATA CLOUD COMPUTING ALL Types Of Machine Learning machine learning using python

list

       
  1. students gallery
  2.    
  3. course
  4.              
                           
    1. west bengal  CLASS 12 COMPUTER SCIENCE
    2.                    
    3. west bengal  CLASS 12 COMPUTER APPLICATION
    4.                    
    5. west bengal  CLASS 11 COMPUTER SCIENCE
    6.                    
    7. west bengal  CLASS 11 COMPUTER APPLICATION
    8.                    
    9. CBCS COMPUTER SCIENCE NEW SYLLABUS( UNIVERSITY OF CALCUTTA )
    10.                                                                                                            
      SEM 1 SEM 2 SEM 3
      SEM 4 SEM 5 SEM 6
                         
    11. CBCS COMPUTER SCIENCE NEW SYLLABUS ( WEST BENGAL STATE UNIVERSITY )
    12.                                                                                                            
      SEM 1SEM 2SEM 3
      SEM 4SEM 5SEM 6
                         
    13. BCA
    14.                    
    15. MCA
    16.                    
    17. CBSE 12
    18.                    
    19. ISC 12
    20.                    
    21. CBSE 11
    22.                    
    23. ISC 11
    24.                    
    25. WEST BENGAL BOARD
    26.                                                                                                                                                     
      CLASS-4CLASS-5CLASS-6
      CLASS-7CLASS-8CLASS-9
      CLASS10CLASS11 applicationCLASS12 application
      CLASS11 scienceCLASS12 science
                              
    27. CBSE BOARD 
    28.                                                                                                                                                     
      CLASS 4CLASS 5CLASS 6
      CLASS 7CLASS 8CLASS 9
      CLASS 10CLASS11CLASS12
                           
    29. ISCE & ISC
    30.                                                                                                                                                       
      CLASS 4CLASS 5CLASS 6
      CLASS 7CLASS 8CLASS 9
      CLASS 10CLASS11CLASS12
                     
          
  5. language AND SOFTWARE
  6.              
                         
    1. MS OFFICE
    2.                    
    3. c
    4.                    
    5. c++
    6.                    
    7. core java
    8.                    
    9. advanced java
    10.                    
    11. visual basic 6
    12.                    
    13. sql
    14.                    
    15. python
    16.                    
    17. R
    18.              
       
  7. java
    1. core java
    2. advanced java
                                                
  8. microprocessor
  9.                
    • 8085 theory
    •                    
    • 8085 question set
    •                          
                                     
      1. 8085 question set (Gaonkar)
      2.                             
                         
    • program code
    •                        
                                       
      1. 8085 assignment list for BSC, BCA,MCA
      2.                              
      3. 8085 assignment code
      4.                              
      5. 8085 op code
      6.                              
      7.   8086
      8.                        
                   
       
  10. digital
  11.                    
                               
    • theory
    •                                
      1. Theory question set - CLICK HERE
      2.                                  
      3. sequential question set 1
      4.                                  
      5. register question
      6.                                  
      7. counter question
      8.                                  
                                 
    • practical
    •                                                            
       
  12. basic electronics
  13.                  
                               
    • theory
    •                              
                                               
      1. question set 1
      2.                                        
      3. question set 2
      4.                              
                               
    • practical
    •                          
    • question set
    •                  
       
  14. architecture/organization
  15.                    
                               
    • theory
    •                          
    • practical
    •                                
        assembly languiage
                               
    • question set
    •                                
                                             
      1. question set 1
      2.                                                                      
                         
       
  16. data structure
  17.                            
                                       
    • theory
    •                                                                                                      
    • practical
    •                            
    • question set
    •                                  
                                             
      1. sorting question
      2.                                  
                                                                            
       
  18. system software
  19.                        
         
    • theory
    •                          
    • practical
    •                          
    • question set
       
  20. operating system
  21.                  
                               
    • theory
    •                          
    • question set
    •                                      
                                                     
      1. question set
      2.                                      
                               
    • practical
    •                  
       
  22. c language
  23.                  
                             
    • theory
    •                                
                                           
      1. theory
      2.                                
                             
    • practical
    •                              
                                           
      1. basic program
      2.                                    
      3. data structure
      4.                                    
      5. numerical analysis
      6.                                    
      7. graph theory
      8.                                    
      9. sorting & searching
      10.                                    
      11. file programming
      12.                                    
      13. bitwise operator
      14.                                    
      15. recursion
      16.                              
                             
    • question set
    •                  
       
  24. graph theory
  25.                          
    • theory
    •                          
    • practical
    •                          
    • question set
       
  26. discrete mathematics
  27.                          
    • theory
    •                          
    • practical
    •                          
    • question set
       
  28. numerical analysis
  29.                      
                                 
    • theory
    •                            
    • practical
    •                                
      1. bisection
                                 
    • question set
    •                      
       
  30. formal languages and automata
  31.                      
    • theory
    •                      
    • practical
    •                      
    • question set
       
  32. networking
  33.                      
    • theory
    •                          
    • practical
    •                          
    • question set
    •                        
                                     
      1. question set
      2.                        
       
  34. graphics
  35.                    
                             
    • theory
    •                                
                                                 
      1. question set
      2.                                          
      3.                                
                                 
        1. practiical
        2.                          
        3. question set
        4.                    
       
  36. c++
  37.                  
                           
    • theory
    •                                    
                                                     
      1. question set
      2.                                                                  
      3. practical
      4.                                    
                                                                                              
        1. this function
        2.                                          
        3. UGC cbcs assignment
        4.                                          
        5. array insertion and deletion
        6.                                    
                         
    • question set
    •                  
       
  38. sofware engineering
  39.                    
    • theory
    •                          
    • practical
    •                          
    • question set
    •                            
                                         
      1. question set
      2.                            
       
  40. dbms
  41.              
                         
    • theory
    •                                          
                                                       
      1. question set
      2.                                          
                         
    • practical
    •                              
                                         
      1. SQL
      2.                                                                
                   
    • question set
       
  42. image processing
  43.                          
    • theory
    •                          
    • practical
    •                          
    • question set
       
  44. information retrieval
  45.                            
    • theory
    •                          
    • practical
    •                          
    • question set
       
  46. unix
  47.            
                         
    1. unix command - set1
    2.                    
    3. unix command - set2
    4.                    
    5. unix command - set3
    6.                    
    7. shell program
    8.            
       
  48. dos
  49.              
                         
    1. dos command - set1
    2.                                
            
  50. vb
  51.              
                         
    • theory
    •                    
    • practical
    •                        
                                     
      1. basic program
      2.                              
      3. vb-oracle connection
      4.                        
                   
    • question set
         
  52. syllabus
  53.                                                                                                                                                                                                         
    CU BSC computer science old syllabusWBSU BSC computer science old syllabus
    CU cbcs BSC computer science HONOURS  syllabus 2018WBSU cbcs BSc computer science HONOURS syllabus 2018
    CU cbcs BSC computer science GENERAL syllabus 2018WBSU cbcs BSC computer science GENERAL syllabus 2018
                          

Blog Archive

  • ▼  2026 (291)
    • ►  October (6)
    • ►  September (120)
    • ▼  August (107)
      • ➕ ARRAY INSERTION AT FRONT
      • 🗑️ ARRAY DELETION AT FRONT
      • ⚡ QUICK SORT VISUALIZER
      • 🏔️ HEAP SORT VISUALIZER
      • 🔀 MERGE SORT VISUALIZER
      • 🔵 BUBBLE SORT VISUALIZER
      • DOUBLE HASHING VISUALIZER
      • 🔷 QUADRATIC PROBING VISUALIZER
      • 🔷 LINEAR PROBING VISUALIZER
      • 🔶 INSERTION SORT VISUALIZER
      • 🔷 SELECTION SORT VISUALIZER
      • ⚡ BINARY SEARCH VISUALIZER
      • LINEAR SEARCH VISUALIZER
      • 🌳 MULTILEVEL INDEXING USING B-TREE & B+ TREE
      • 📚 INDEXING STRUCTURES FOR FILES
      • 📁 FILES OF UNORDERED AND ORDERED RECORDS
      • 📁 FILE OPERATIONS IN DBMS
      • 🔄 CONCURRENCY CONTROL IN DBMS
      • ACID PROPERTIES IN DBMS
      • 🗄️ DBMS ANOMALIES & NORMALIZATION Insertion • Upd...
      • 🔐 LOSSLESS DECOMPOSITION
      • 🔗 FUNCTIONAL DEPENDENCY
      • 🧩 EER MODEL — INTERACTIVE LEARNING
      • 🗄️ SQL INTERACTIVE LEARNING
      • 🧮 RELATIONAL ALGEBRA
      • 🔐 Database Constraints
      • 🗂️ Basic ER Diagram
      • 🔐 Data Independence
      • 🏗️ Database Architecture
      • 🗄️ Database Models
      • 🌳 Decision Tree Using ANN-Style Visualization Ste...
      • 🧠 KNN Using an ANN-Style Learning Model Step-by-s...
      • 🧠 K-Means Clustering with ANN-Style Explanation
      • 🌸 K-Nearest Neighbors (KNN)
      • 🌳 Decision Tree Using Iris Dataset
      • 🌸 K-Means Clustering Using Iris Dataset
      • ANN Credit Card Approval — Weight & Bias Update
      • 🧠 ANN Backpropagation: Weight & Bias Update A sim...
      • 🧠 Three-Layer ANN — Digit Recognition Step-by-ste...
      • 🧠 Two-Layer ANN — Step-by-Step Mathematics Exampl...
      • 🔢 ANN Handwritten Digit Recognition Example: Reco...
      • 🧠 ANN Logic Gates — Complete Step-by-Step Mathema...
      • 🔢 ANN Example: Handwritten Digit Recognition
      • 🌐 ANN + NLP Example: Language Detection Use Natur...
      • 📧 ANN + NLP Example: Spam Email Detection
      • Use Natural Language Processing features and an Ar...
      • 🏠 ANN Example: House Price Prediction
      • 🧠 ANN Example: Student Result Prediction
      • 🧠 ANN Example: Loan Approval Prediction
      • 🧠 Artificial Neural Network for Credit Card Approval
      • ACTIVATION FUNCTION USED IN ANN
      • ARTIFICIAL NEURAL NETWORK
      • CONFUSION MATRIX
      • St Jude's High School class -10
      • Chapter 1: Operating System and Graphical User Int...
      • Chapter 5: Charts in Excel St Jude's High School ...
      • Chapter 4: Formulas and Functions in Excel St Jude...
      • Chapter 6: Conditional Statements in BlueJ St Jud...
      • Chapter 8: Advanced Features of HTML St Jude's Hig...
      • Chapter 3: Computer Virus St Jude's High School c...
      • Chapter 2 : Number System St Jude's High School ...
      • Chapter 1: Internal and External Hardware Componen...
      • Chapter 4: Mail Merge St Jude's High School class -6
      • Chapter 3: Working with Tables (St Jude's High Sch...
      • Chapter 2: Managing Files and Folders (St Jude's H...
      • Chapter 1: Classification of Computers and Languag...
      • Chapter 1: Evolution of Computers (St Jude's High ...
      • Chapter 2: Types of Software(St Jude's High School...
      • Chapter 3: Formatting in Word Processor (St Jude's...
      • Chapter 4: Advanced Features of Word Processor — I...
      • k means clustering using iris dataset step by step...
      • Database Management Systems Theory:
      • HUFFMAN ALGORITHM ONLINE TOOL
      • Image Morphing & Spatial Transformations
      • Image Morphing
      • Huffman Coding Algorithm
      • IMAGE PROCESSING
      • MEAN MEDIAN MODE
      • Basic Statistical Descriptions of Data
      • Measuring Data Similarity and Dissimilarity
      • Data Warehouses:
      • Data Mining as a Step in the Process of Knowledge ...
      • Scikit-Learn Models
      • Deep Learning (Neural Networks)
      • Reinforcement Learning
      • Semi-Supervised Learning:
      • Unsupervised Learning Models
      • Supervised Learning Models
      • Different type of models used in Machine Learning ...
      • HOW TO TRAIN A MODEL STEP BY STEP IN PYTHON
      • Python Online frame
      • mglearn
      • Pandas for data science
      • matplotlib
      • SciPy
      • NumPy
      • scikit-learn
      • 4. image input and display (gray scale)
      • 8. Image Thresholding using OpenCV (or Image Binar...
      • 7. Image Thresholding using OpenCV (or Image Binar...
      • 6. OpenCV image reading and writing
      • 5. OpenCV image reading and writing
      • 3. Get number of pixel, dimension of image
      • 2. image input and display (color)
      • 1. image input and display
      • MACHINE LEARNING USING PYTHON
      • Image Processing using Python OpenCV
    • ►  July (11)
    • ►  June (26)
    • ►  April (4)
    • ►  February (8)
    • ►  January (9)
  • ►  2025 (23)
    • ►  December (3)
    • ►  November (4)
    • ►  March (11)
    • ►  February (5)
  • ►  2024 (134)
    • ►  November (13)
    • ►  August (12)
    • ►  July (1)
    • ►  June (5)
    • ►  March (47)
    • ►  February (50)
    • ►  January (6)
  • ►  2023 (105)
    • ►  December (1)
    • ►  October (2)
    • ►  September (1)
    • ►  August (13)
    • ►  July (64)
    • ►  March (1)
    • ►  January (23)
  • ►  2022 (31)
    • ►  October (1)
    • ►  June (1)
    • ►  May (29)
  • ►  2021 (72)
    • ►  December (14)
    • ►  May (11)
    • ►  February (22)
    • ►  January (25)
  • ►  2020 (564)
    • ►  December (33)
    • ►  November (123)
    • ►  October (16)
    • ►  August (1)
    • ►  June (87)
    • ►  May (83)
    • ►  April (221)
  • ►  2019 (115)
    • ►  December (2)
    • ►  September (1)
    • ►  August (1)
    • ►  May (9)
    • ►  April (46)
    • ►  March (42)
    • ►  February (14)
  • ►  2018 (1)
    • ►  December (1)
  • ►  2017 (7)
    • ►  August (1)
    • ►  July (3)
    • ►  January (3)
  • ►  2016 (22)
    • ►  November (5)
    • ►  September (1)
    • ►  August (1)
    • ►  July (3)
    • ►  June (10)
    • ►  May (2)
  • ►  2015 (3)
    • ►  December (2)
    • ►  September (1)
  • ►  2014 (3)
    • ►  September (1)
    • ►  March (1)
    • ►  January (1)
  • ►  2013 (44)
    • ►  October (4)
    • ►  September (9)
    • ►  July (2)
    • ►  June (1)
    • ►  May (7)
    • ►  April (7)
    • ►  March (12)
    • ►  February (1)
    • ►  January (1)

About Me

bijan krishna paul
View my complete profile
Watermark theme. Powered by Blogger.