我正在尝试利用 scipy.stats.linregress() 函数。我仔细检查了我的两个输入的大小相同并且都是数组。但是我不断收到以下错误:
Traceback (most recent call last):
File "C:/Users/chianh/Desktop/Reliability Py Scripts/MedianRanks_Solver_Rev0.py", line 48, in <module>
slope, intercept, r_value, p_value, std_err = stats.linregress(data, median_rank)
File "C:\Users\chianh\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scipy\stats\_stats_mstats_common.py", line 81, in linregress
r_den = np.sqrt(ssxm * ssym)
AttributeError: 'Float' object has no attribute 'sqrt'
Run Code Online (Sandbox Code Playgroud)
我写的代码粘贴在下面:
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8870 次 |
| 最近记录: |