AI ?????? ML ?????? ????????? Python ????????? OOPs: ???????????????????????? ?????? ????????? ????????????
Object-Oriented Programming (OOPs) Python ?????? ?????? ??????????????????????????? ??????????????????????????? ??????, ?????? ??????????????????????????? ??????????????????????????? ?????? ????????????????????????, ???????????????????????????, ?????? ??????????????????????????? ??????????????? ????????? Artificial Intelligence (AI) ?????? Machine Learning (ML) ????????? OOPs ?????? ??????????????? ??????????????????, ???????????? ?????????????????????????????????, ?????? ?????????????????????????????? ?????? ??????????????????????????? ???????????? ?????? ????????? ???????????? ????????? ?????? ??????????????? ?????????, ?????? Python ????????? OOPs ?????? ??????????????? ?????? ?????????????????????????????? ????????????????????????????????? ?????? ??????????????? ??????????????????????????? ??????????????????, ???????????? ?????????????????????, ??????????????????????????????, ??????????????????????????????, ????????????????????????????????????, ?????? ???????????????????????????????????????
?????? ??????????????? ?????? ???????????????????????? ???????????????????????? ?????? ?????????????????????????????? ????????????????????? ?????? OOPs ?????? ?????????????????? ????????????????????????????????? ?????????????????? ??????, ?????? AI/ML ????????????????????????????????? ?????? ???????????? ???????????? ???????????? ?????? ?????? ??????????????????????????? ?????? ????????? ????????????????????????????????????, AI/ML ????????? ???????????? ???????????? ?????????, ?????? ?????????????????????????????? ??????????????? ?????? ????????? ????????? ?????????????????????
OOPs ???????????? ??????? - What is OOPs in Hindi?
OOPs ?????? ???????????????????????????????????? ???????????????????????? ?????? ?????? ?????????????????????????????? ?????? ????????????????????? ?????? ????????????-??????????????? ????????? ???????????? ????????? ?????? ????????? ?????? ??????????????????????????? ???????????? ?????? ?????? ??????????????? ??????, ?????????????????? ???????????? (attributes) ?????? ???????????????????????? (methods) ?????? ?????? ????????? ??????????????? ???????????? ????????? Python ????????? OOPs AI ?????? ML ?????? ????????? ????????? ????????? ?????? ?????????????????? ?????? ????????????????????? ?????? ?????????????????? ?????? ???????????? ????????????????????????????????? ?????? ??????????????? ???????????? ????????? ????????? ???????????? ?????????
OOPs ?????? ?????????????????? ?????????????????????????????????:
-
????????????????????? ?????? ??????????????????????????????: ???????????? ?????? ???????????????????????? ?????? ?????? ??????????????? ????????? ?????????????????????
-
??????????????????????????????: ????????? ?????????????????? ???????????? ?????? ????????? ?????? ??????????????? ?????? ????????????????????????????????? ?????? ??????????????? ??????????????? ????????? ????????? ???????????????
-
????????????????????????????????????: ?????? ?????? ?????????????????? ?????? ?????????-????????? ?????????????????? ?????? ???????????? ???????????????
-
????????????????????????????????????: ???????????? ?????? ??????????????????????????? ???????????? ?????? ?????????????????? ????????????????????? ?????? ?????????????????????
AI/ML ????????? ???????????? ?????????: OOPs ?????? ??????????????? ML ?????????????????? (???????????? Scikit-learn's estimators) ?????? ????????? ????????????????????? ????????????????????????????????? (???????????? Neural networks of PyTorch) ????????? ???????????? ?????????
Python ????????? OOPs ?????? ??????????????? ????????????????????????????????? - Basic Concepts of OOPs in Python in Hindi
1. ????????????????????? ?????? ?????????????????????????????? - Classes and Objects
??????????????? ?????? ?????????????????????????????? ??????, ?????? ?????????????????????????????? ?????? ?????????????????? ???????????? ??????, ?????? ???????????????????????? ?????? ?????????????????????????????? ?????? ?????? ???????????????????????? ???????????? ????????? AI/ML ????????? ????????????????????? ?????? ???????????? ?????????????????? ?????? ???????????? ????????????????????????????????? ?????? ?????????????????? ???????????? ?????? ????????? ???????????? ?????????
????????? ??????????????????????????????: ?????? ML ???????????? ?????? ????????? ??????????????? ??????????????????
# Class for ML model
class MLModel:
def __init__(self, name, accuracy):
self.name = name # Attribute
self.accuracy = accuracy
def display_info(self): # Method
print(f"Model Name: {self.name}, Accuracy: {self.accuracy}%")
# Create an object
model = MLModel("Decision_Tree", 92.5)
model.display_info()
??????????????????:
Model Name: Decision_Tree, Accuracy: 92.5%
AI/ML ????????? ????????????: ????????????????????? ?????? ???????????? ML ?????????????????? (???????????? classifiers) ?????? ?????????????????? ???????????? ?????? ???????????? ????????????????????????????????? (???????????? accuracy, parameters) ?????? ??????????????? ???????????? ?????? ????????? ???????????? ?????????
2. ?????????????????????????????? - Inheritance
?????????????????????????????? ?????? ??????????????? ?????? ??????????????? ??????????????? ?????? ????????????????????????????????? ?????? ?????????????????? ?????? ?????????????????? ???????????? ?????? ?????????????????? ???????????? ????????? ?????? AI/ML ????????? ????????? ?????? ???????????????????????? ??????????????? ?????? ????????? ?????????????????? ?????????
????????? ??????????????????????????????: ?????? ????????? ML ???????????? ?????? ????????????????????? ???????????????
# Base class
class BaseMLModel:
def __init__(self, name):
self.name = name
def train(self):
print(f"{self.name} is training...")
# Inherited Class
class RegressionModel(BaseMLModel):
def predict(self, input_data):
print(f"{self.name} is predicting on {input_data}")
# Create an object
reg_model = RegressionModel("Linear_Regression")
reg_model.train()
reg_model.predict("test_data")
??????????????????:
Linear_Regression is training...
Linear_Regression is predicting on test_data
AI/ML ????????? ????????????: ?????????????????????????????? ?????? ???????????? ML ????????????????????????????????? ????????? ????????? ?????????????????? (???????????? Base Estimator of Scikit-learn) ?????? ??????????????? ?????????????????? ??????????????? ?????? ????????? ???????????? ?????????
3. ???????????????????????????????????? - Polymorphism
???????????????????????????????????? ?????? ???????????? ?????? ?????? ?????? ?????? ???????????? ?????????-????????? ????????????????????? ????????? ?????????-????????? ??????????????? ?????? ????????? ?????? ???????????? ????????? ?????? AI/ML ????????? ?????????????????????????????? ????????? ??????????????? ????????? ????????? ???????????? ?????????
????????? ??????????????????????????????: ???????????????????????????????????? ?????? ???????????????
# Base class
class MLModel:
def predict(self):
pass
# Derived classes
class DecisionTree(MLModel):
def predict(self):
print("Predicting using Decision Tree algorithm")
class NeuralNetwork(MLModel):
def predict(self):
print("Predicting using Neural Network algorithm")
# Polymorphism
models = [DecisionTree(), NeuralNetwork()]
for model in models:
model.predict()
??????????????????:
Predicting using Decision Tree algorithm
Predicting using Neural Network algorithm
AI/ML ????????? ????????????: ???????????????????????????????????? ?????? ???????????? ?????????-????????? ML ?????????????????? ?????? ????????? ?????? ???????????? ????????????????????? (???????????? predict) ??????????????? ????????? ???????????? ?????????
4. ???????????????????????????????????? - Encapsulation
???????????????????????????????????? ???????????? ?????? ??????????????????????????? ???????????? ?????? ?????????????????? ????????????????????? ?????? ?????????????????? ?????? ??????????????? ????????? Python ????????? ???????????????????????? ??????????????????????????? _ ?????? __ prefix se ???????????? ???????????? ????????????
????????? ??????????????????????????????: ???????????????????????????????????? ?????? ???????????????
# Class with encapsulation
class MLModel:
def __init__(self, name, accuracy):
self.__name = name # Private variable
self.__accuracy = accuracy
def set_accuracy(self, accuracy): # setter
if accuracy >= 0 and accuracy <= 100:
self.__accuracy = accuracy
else:
print("Invalid accuracy value")
def get_accuracy(self): # gaiter
return self.__accuracy
# Creating an object
model = MLModel("SVM", 88.5)
print("Accuracy:", model.get_accuracy())
model.set_accuracy(95.0)
print("Updated Accuracy:", model.get_accuracy())
??????????????????:
Accuracy: 88.5
Updated Accuracy: 95.0
AI/ML ????????? ????????????: ???????????????????????????????????? ?????? ???????????? ???????????? ?????????????????????????????? (???????????? weights, biases) ?????? ??????????????????????????? ???????????? ?????? ???????????????????????? ????????????????????? ?????? ????????? ???????????? ?????????
AI ?????? ML ????????? OOPs ?????? ??????????????? - Advantages of OOPs in AI & ML in Hindi
-
?????????????????????????????????: ????????? ?????? ????????????-???????????? ??????????????????????????? ????????? ?????????????????? ??????????????????????????? ???????????? ???????????? ?????????
-
???????????????????????????????????????: ?????????????????????????????? ?????? ???????????????????????????????????? ?????? ??????????????? ????????? ?????? ?????????????????? ???????????? ???????????? ?????? ???????????? ?????????
-
???????????????????????????????????????: ???????????????????????????????????? ?????? ????????? ?????? ??????????????? ?????? ?????????????????? ???????????? ???????????? ???????????? ?????????
-
????????????????????????????????????: ???????????? AI/ML ????????????????????????????????? ????????? OOPs ?????????????????? ?????? ??????????????? ???????????? ????????? ????????? ???????????? ?????????
AI ?????? ML ????????? OOPs ?????? ???????????? ????????? - Use Cases of OOPs in AI & ML in Hindi
-
ML ?????????????????? ????????????????????? ????????????: Scikit-learn, PyTorch, ?????? TensorFlow ???????????? ????????????????????????????????? OOPs ?????? ???????????? ???????????? ????????????
-
???????????? ??????????????????????????????: ???????????? ?????????????????????????????????????????? ?????? ???????????? ????????????????????????????????? ?????? ????????? ????????????????????? ??????????????????
-
??????????????? ??????????????????: ?????????????????? ??????????????????????????? ?????? ??????????????? ????????????????????????????????? ?????? ????????????????????? ????????? ?????????????????? ???????????????
-
???????????? ???????????????????????????: ?????????????????? ?????? ????????????????????????, ????????????????????????, ?????? ????????????????????????????????? ?????? ????????? OOPs ??????????????????????????????
???????????? ??????????????????????????? ??????????????????: ?????? ?????????????????? ML ???????????? ??????????????? ??????????????? ?????? ???????????? ??????????????? ???????????? ?????????????????????????????? ?????? ??????????????????????????? ???????????????????????? ????????????
# Mini Project: Basic ML Model Class
class SimpleMLModel:
def __init__(self, name):
self.name = name
self.data = []
def add_data(self, data_point):
self.data.append(data_point)
def calculate_accuracy(self):
if not self.data:
return 0
correct = sum(1 for x in self.data if x > 0.5) # Dummy logic
return (correct / len(self.data)) * 100
# Creating an object
model = SimpleMLModel("Dummy_Model")
model.add_data(0.7)
model.add_data(0.9)
model.add_data(0.3)
print("Model Accuracy:", model.calculate_accuracy(), "%")
??????????????????:
Model Accuracy: 66.66666666666666 %
Python ????????? OOPs ?????? ??????????????? ????????????????????????????????? - Best Practices in OOPs in Hindi
-
??????????????????????????? ??????????????????: ??????????????? ?????? ???????????? ??????????????? ??????????????????????????????????????? ???????????? (???????????? MLModel instead of Model).
-
???????????????????????????????????? ?????? ????????????: ???????????????????????? ??????????????????????????? ?????? ????????????/???????????? ?????????????????? ???????????? ???????????????
-
???????????????????????? ?????????: ???????????? ?????? ??????????????????????????? ????????????????????? ??????????????????
-
???????????????????????????????????????: ?????? ??????????????? ?????? ???????????? ?????? ????????? ????????????????????? ?????? ??????????????????????????????????????? ?????????????????????
???????????????????????? - Conclusion
Python ????????? Object-Oriented Programming (OOPs) ?????? ??????????????????????????? ????????? ?????? ?????? AI ?????? ML ????????????????????????????????? ?????? ??????????????????????????? ?????? ??????????????? ???????????? ????????? ????????? ???????????? ????????? ?????? ??????????????? ????????? ???????????? OOPs ?????? ??????????????? ????????????????????????????????? ???????????? ?????????????????????, ??????????????????????????????, ????????????????????????????????????, ?????? ???????????????????????????????????? ?????? ??????????????? ??????????????????????????? ????????????, ????????? ?????? AI/ML ????????? ???????????? ???????????? ????????? ?????? ?????? ????????? ???????????????
???????????? ????????????????????? ????????? ?????? NumPy, Pandas, ?????? Matplotlib ???????????? ?????????????????????????????? ?????? ??????????????? ??????????????????????????? ??????????????????, ?????? AI/ML ????????????????????????????????? ????????? ???????????? ?????????????????????????????? ????????????????????????????????? ?????? ??????????????????????????? ??????????????????????????? ???????????? ???????????? ?????? ???????????? AI/ML ????????????????????????????????? ????????? OOPs ?????? ??????????????? ????????????!
Also Read:??