Resolved mypy checks

This commit is contained in:
Harmanaya Sharma 2024-10-23 00:20:29 +05:30
parent 8f1f091aa4
commit 5bf9b854b4

View File

@ -1,5 +1,6 @@
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from typing import Optional, Tuple
class RidgeRegression: class RidgeRegression:
@ -15,7 +16,7 @@ class RidgeRegression:
self.alpha = alpha self.alpha = alpha
self.lambda_ = lambda_ self.lambda_ = lambda_
self.iterations = iterations self.iterations = iterations
self.theta = None self.theta: Optional[np.ndarray] = None # Initialize as None, later will be ndarray
def feature_scaling( def feature_scaling(
self, features: np.ndarray self, features: np.ndarray
@ -92,6 +93,9 @@ class RidgeRegression:
>>> predictions.shape == target.shape >>> predictions.shape == target.shape
True True
""" """
if self.theta is None:
raise ValueError("Model is not trained yet. Call the `fit` method first.")
features_scaled, _, _ = self.feature_scaling( features_scaled, _, _ = self.feature_scaling(
features features
) # Scale features using training data ) # Scale features using training data
@ -114,6 +118,9 @@ class RidgeRegression:
>>> isinstance(cost, float) >>> isinstance(cost, float)
True True
""" """
if self.theta is None:
raise ValueError("Model is not trained yet. Call the `fit` method first.")
features_scaled, _, _ = self.feature_scaling( features_scaled, _, _ = self.feature_scaling(
features features
) # Scale features using training data ) # Scale features using training data