Sort by

recency

|

46 Discussions

|

  • + 1 comment
    import numpy as np
    from sklearn.linear_model import LinearRegression
    
    Physics = [  15,  12,  8,   8,   7,   7,   7,   6,   5,   3]
    History = [ 10,  25,  17,  11,  13,  17,  20,  13,  9,   15]
    
    #Sample data
    X = np.array(Physics).reshape((-1, 1))
    y = np.array(History)
    
    #Create and train the model
    model = LinearRegression()
    model.fit(X, y)
    
    #Get the slope (coefficient)
    slope = model.coef_[0]
    slope
    
  • + 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)))