我正在尝试使用scipy.stats.linregress()函数。我仔细检查了我的两个输入都是相同的大小,都是数组。但是我一直收到以下错误:
import numpy as np
import matplotlib.pyplot as plot
import scipy.stats as stats
from sympy import Symbol, binomial, expand_func, solve, solveset
def eval_median_rank( mylist ):
P = 0.5 # Percentage Point (would be 0.5 to be median)
Z = Symbol('Z', real=True) # Median Rank (Should be solved for each test unit)
result = [] # Place holder for the evaluated Median Ranks
# Re-iterate and perform for each data point
for j in range(1, mylist.size+1):
eq = 0
k = j
# Generate the Median Rank equation which will be solved for 'Z' or Median Rank
while k <= mylist.size:
eq = eq + expand_func(binomial(mylist.size, k) * (Z**k) * (1 - Z)**(mylist.size-k))
k += 1
eq = eq - P
# Solve for only Median Rank solutions that only fall between 0 and 1.
# Then append to the returning list
sol = [i for i in solve(eq, Z, list=True) if (i > 0) and (i < 1)]
result.extend(sol)
result.sort(reverse=True)
return np.array(result)
######################################################################################################
# Note that the samples must be ordered in ascending fail-time/UOM,
# and the system must be solved in that order.
data = np.array([96, 257, 498, 763, 1051, 1744], dtype=object)
rank = np.arange(1, data.size+1)
median_rank = eval_median_rank(rank)
print(median_rank)
# Use Scipy's stats package to perform Least-Squares fit
slope, intercept, r_value, p_value, std_err = stats.linregress(data, median_rank)
我写的代码粘贴在下面:
{{1}}