Sunday, 11 January 2026

Linear Regression experiment 2- Experience vs Salary Prediction

 

Experience vs Salary Prediction (Linear Regression  Code)

(Real-life Example)


Problem Statement

Predict salary based on years of experience


Step 1: Import Libraries

import pandas as pd from sklearn.linear_model import LinearRegression

Step 2: Create Dataset

data = { 'Experience': [1, 2, 3, 4, 5], 'Salary': [15000, 20000, 30000, 40000, 50000] } df = pd.DataFrame(da ta)

Explain:

  • Experience → Input

  • Salary → Output


Step 3: Divide Data

X = df[['Experience']] y = df['Salary']

Step 4: Train Model

model = LinearRegression() model.fit(X, y)

Explain:

  • Model learns how salary grows with experience


Step 5: Predict Salary

salary = model.predict([[6]]) print("Predicted Salary:", salary)

Explain:

  • Predict salary for 6 years experience

No comments:

Post a Comment

Blockchain technology

  Blockchain technology is a decentralized, distributed digital ledger that securely records transactions across many computers, creating an...