首页 > 其他 > 详细

Statistics and Linear Algebra 3

时间:2016-12-01 07:34:49      阅读:215      评论:0      收藏:0      [点我收藏+]

1. Get the r value and the p value between the dataset:

  r_fta_pts,p_value = pearsonr(nba_stats["pts"],nba_stats["fta"]) 

  r_stl_pf,p_value = pearsonr(nba_stats["stl"],nba_stats["pf"]) # It will return R value and P value.

2. The function of getting convariance form two data set, the convariance is the value that measure how much two variables correlated with each other. If one changes to bigger, the other changes to bigger. which said these two variables are corresponse. Here is the function of getting the convariance:

here is the formular:

 技术分享

  def conv_compute(x,y): #define a function to calculate the convariance

  mean_x = sum(x)/len(x)
  mean_y = sum(y)/len(y)# calculate the mean of each column
  x_diff = [i-mean_x for i in x]
  y_diff = [n-mean_y for n in y] # calculate the difference for both column, if it is hard to use for loop, we can think about the list function.
  sum_diff =[x_diff[i]* y_diff[i] for i in range(len(x))] # use range(len()) function to replace the for loop
  return sum(sum_diff)/len(sum_diff)

  cov_stl_pf = conv_compute(nba_stats["stl"],nba_stats["pf"])
  cov_fta_pts = conv_compute(nba_stats["fta"],nba_stats["pts"])

3. The way to calculate correlation coefficient: The fomular is 技术分享

  from numpy import cov

  cov_1 = cov(nba_stats["fta"],nba_stats["blk"])[0,1]
  std_1 = nba_stats["fta"].std() * nba_stats["blk"].std()
  r_fta_blk = cov_1/std_1

  

Statistics and Linear Algebra 3

原文:http://www.cnblogs.com/kingoscar/p/6120469.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!