• + 1 comment
    class LR:
        def __init__(self):
            self.slope = None
            self.intercept = None
            
        def fit(self, x, y):
            x_avg = sum(x)/x.__len__()
            y_avg = sum(y)/y.__len__()
            numerator = sum([(a - x_avg)*(b - y_avg) for a,b in zip(x,y)])
            denominator = sum([(a - x_avg)**2 for a in x])
            self.slope = round(numerator/denominator, 3)
            self.intercept = y_avg - self.slope*x_avg
        def predict(self, x):
            if self.slope and self.intercept:
                return self.slope*x + self.intercept
            else:
                raise ModuleNotFoundError('predict is not found, call fit() before predict()')
            
    
    if __name__ == '__main__':
        if __name__ == '__main__':
            feature_1 = "Physics Scores  15  12  8   8   7   7   7   6   5   3"
            feature_2 = "History Scores  10  25  17  11  13  17  20  13  9   15"
            feature_1 = [int(x) for x in input().split() if x.isnumeric()]
            feature_2 = [int(x) for x in input().split() if x.isnumeric()]
            model = LR()
            model.fit(feature_1, feature_2)
            out = str(model.predict(10))
            out = out.split('.')
            print(float(out[0] + '.' + out[1][0]))