Linear Regression

Namaste doston! Aaj hum baat karenge ek bahut hi interesting topic ke baare mein – Linear Regression. Yeh Data Science ki duniya ka ek aisa concept hai jo har data scientist ke liye jaanna bahut zaroori hai. Toh chaliye shuru karte hain!

Linear Regression kya hota hai?

Simple bhasha mein kahein toh Linear Regression ek aise model ko fit karne ka tarika hai jo do variables ke beech ke relationship ko samajhne mein madad karta hai. Isme ek variable doosre variable ko predict karne mein help karta hai. Jaise ki:

  • Agar aapke paas ghar ka size hai, toh uske price ka anumaan lagana
  • Padhai ke ghanton se exam marks ka prediction karna
  • Kisi product ki advertising par kiye gaye kharche se uski sales ka estimate lagana

Linear Regression ka Theory

Linear Regression ka basic idea yeh hai ki ek straight line fit karna jo data points ke beech se guzarti ho. Is line ko “best fit line” kehte hain. Yeh line humare prediction ko represent karti hai.

Iska equation hota hai:

y = mx + b

Jahan:

  • y = dependent variable (jo hum predict karna chahte hain)
  • x = independent variable (jiske basis par prediction karte hain)
  • m = slope (line ka dhaalan)
  • b = y-intercept (jahan line y-axis ko cross karti hai)

Ek Real-Life Example: Ghar ki Keemat ka Prediction

Chalo, ek example lete hain. Maan lo aapke paas kuch data hai jisme ghar ka size (square feet mein) aur uski keemat di gayi hai. Ab aap chahte hain ki naye ghar ki keemat ka anumaan lagaya jaa sake uske size ke hisaab se.

  1. Sabse pehle, aap apne paas available data ko plot karenge.
  2. Phir, aap ek aisi line fit karenge jo in points ke beech se guzarti ho.
  3. Is line ka equation nikaalna hoga (y = mx + b).
  4. Ab agar aapke paas kisi naye ghar ka size hai, toh aap is equation mein value daalkar uski keemat ka estimate laga sakte hain!

Code mein Kaise Karein Implement?

Python mein linear regression implement karna bahut aasan hai. Hum sklearn library ka use karenge:

from sklearn.linear_model import LinearRegression
import numpy as np
import matplotlib.pyplot as plt

# Sample data
sizes = np.array([1400, 1600, 1700, 1875, 1100, 1550, 2350, 2450, 1425, 1700]).reshape(-1, 1)
prices = np.array([245000, 312000, 279000, 308000, 199000, 219000, 405000, 324000, 319000, 255000])

# Create and fit the model
model = LinearRegression()
model.fit(sizes, prices)

# Predict for a new house size
new_size = np.array([2000]).reshape(-1, 1)
predicted_price = model.predict(new_size)

print(f"2000 square feet ke ghar ki estimated keemat: ${predicted_price[0]:.2f}")

# Visualize
plt.scatter(sizes, prices, color='blue', label='Actual Data')
plt.plot(sizes, model.predict(sizes), color='red', label='Regression Line')
plt.xlabel('Ghar ka Size (sq ft)')
plt.ylabel('Keemat ($)')
plt.title('Ghar ka Size vs Keemat')
plt.legend()
plt.show()

Is code se aap ek graph bhi dekh sakte hain jisme actual data points aur regression line dono dikhegi.

Conclusion

Toh doston, yeh thi Linear Regression ki ek choti si jhalak. Yeh technique data science mein bahut kaam aati hai, especially jab aap do variables ke beech ke relationship ko samajhna chahte hain aur future predictions karna chahte hain.

Yaad rakhiye, har model perfect nahi hota. Linear Regression bhi kuch assumptions par based hai, aur complex relationships ke liye shayad kaam na aaye. Lekin phir bhi, yeh ek powerful tool hai jo aapko data ki duniya mein ek naya nazariya dega!

Happy Learning! 📊📈🎓

Ajink Gupta
Ajink Gupta

Ajink Gupta is a software developer from Dombivli, Maharashtra, India. He has expertise in a variety of technologies including web development, mobile app development, and blockchain. He works with languages and frameworks like JavaScript, Python, Flutter, React, and Django.

Ajink Gupta is also active on several platforms where he shares his work and engages with the community. You can find his projects and contributions on GitHub and follow his tutorials and updates on his YouTube channel​ . He also has a personal website where he showcases his portfolio and ongoing projects at ajinkgupta.vercel.app

Articles: 61