Sort by

recency

|

31 Discussions

|

  • + 0 comments

    There is something wrong here. I even have were given the equal outcomes with one-of-a-kind Python three libraries, and but the handiest manner it worked become with the aid of printing the real bring about plane textual content for contemporary design.

    Companies are the use of those gear to evaluate their candidates.

  • + 0 comments
    def pearson_correlation(x, y, n):
        mean_x = sum([i for i in x]) / len(x)
        mean_y = sum([i for i in y]) / len(y)
        
        sum_xy = sum([x[i] * y[i] for i in range(n)])
        
        Sx = pow(sum([pow(i - mean_x, 2) for i in x]) / (n-1), 0.5)
        Sy = pow(sum([pow(i - mean_y, 2) for i in y]) / (n-1), 0.5)
        
        corr = (sum_xy - n * mean_x * mean_y) / ((n-1) * Sx * Sy)
        
        return corr
        
    n = int(input())
    data = [list(map(float, input().split())) for i in range(n)]
    
    math = [data[i][0] for i in range(n)]
    physics = [data[i][1] for i in range(n)]
    chem = [data[i][2] for i in range(n)]
    
    print("%.2f" % pearson_correlation(math, physics, n))
    print("%.2f" % pearson_correlation(physics, chem, n))
    print("%.2f" % pearson_correlation(chem, math, n))
    
  • + 0 comments
    from math import sqrt
    x = int(input())
    scores = [list(map(lambda a : float(a), input().split('\t'))) for _ in range(x)]
    m = list(map(lambda a : a[0], scores))
    p = list(map(lambda a : a[1], scores))
    c = list(map(lambda a : a[2], scores))
    
    def correlation(X, Y, N):
        numerator = (N * sum(map(lambda a,b : a*b, X, Y))) - (sum(X)*sum(Y))
        denominator = sqrt(N*sum(map(lambda a : a**2, X)) - (sum(X)**2)) * sqrt(N*sum(map(lambda a : a**2, Y)) - (sum(Y)**2))
        return numerator/denominator
    
    print('%.2f'%(correlation(m,p,x)))
    print('%.2f'%(correlation(p,c,x)))
    print('%.2f'%(correlation(c,m,x)))
    
  • + 0 comments

    how to import numpy here in hackerrank

  • + 0 comments

    Directly from definition:

    em,ep,ec = 0.0,0.0,0.0
    em2,ep2,ec2 = 0.0,0.0,0.0
    emp,emc,epc = 0.0,0.0,0.0
    n = int(input())
    for _ in range(n):
        m,p,c = map(int,input().split())
        em+=m
        ep+=p
        ec+=c
        em2+=m**2
        ep2+=p**2
        ec2+=c**2
        emp+=m*p
        emc+=m*c
        epc+=p*c
    
    rmp=(n*emp-em*ep)/((n*em2-(em)**2)*(n*ep2-(ep)**2))**0.5
    rpc=(n*epc-ec*ep)/((n*ec2-(ec)**2)*(n*ep2-(ep)**2))**0.5
    rmc=(n*emc-em*ec)/((n*em2-(em)**2)*(n*ec2-(ec)**2))**0.5
    
    print('%.2f\n%.2f\n%.2f' %(rmp,rpc,rmc))
    

    exy actually means sum rather than expectation