Sort by

recency

|

45 Discussions

|

  • + 0 comments

    Help !!

    new to hackerRank , how to debug here ?? what's the expected input and output format ? This code runs perfect locally....

    import numpy as np from sklearn.linear_model import LinearRegression

    def return_cof(x,Y): x=np.array(x).reshape(-1, 1) y = np.array(Y).reshape(-1, 1) reg=LinearRegression().fit(x,Y) ans=reg.coef_ return round(ans[0],3)

    a=[15,12,8,8,7,7,7,6,5,3] b=[10,25,17,11,13,17,20,13,9,15] ans=return_cof(a,b) print(ans)

  • + 0 comments

    Does anyone know why I am getting this error? Thank you

    import numpy as np ModuleNotFoundError: No module named 'numpy'

  • + 0 comments

    Common irritation here:
    * no input is provided in this excercise, hardcode it if needed
    * "(your answer) in the textbox" just print your answer to stdout

  • + 1 comment

    The following code must work but I think the env under the submit is faulty and doesn't let anything but simple print statements to run.

    def get_coeff(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])
        return round(numerator/denominator, 3)
    
    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()]
        print(str(get_coeff(feature_1,feature_2)))
    
  • + 0 comments

    My Solution:

    def get_regr_slope(x,y):
        xy = [a*b for a, b in zip(x,y)]
        n = len(x)
        x_2 = [a*a for a in x]
        num = n*sum(xy) - sum(x)*sum(y)
        denom = n*sum(x_2) - sum(x)**2
        slope = num/denom
        print("%.3f" % slope)
    
    physics = [15, 12, 8, 8, 7, 7, 7, 6, 5, 3]
    history = [10, 25, 17, 11, 13, 17, 20, 13, 9, 15]
    
    
    get_regr_slope(physics, history)