- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试将一些线性线拟合到曲线上,它们在 0 附近表现出线性,然后做一些奇怪的事情。但我需要他们的行为为零。现在我已经编写了一个小脚本,它对于某些曲线根本不起作用,而对于其他曲线则完美。我不确定为什么,你能帮忙吗?
def linfit(mode): #linfit a line trough 3 dots around 0
x = [-2,-1,0,1,2] #Grab a few points around 0 and fit a line
y = [1,2,3,4,5] #put the middle 5 values from input into y
y[0] = mode[8]
y[1] = mode[9]
y[2] = mode[10]
y[3] = mode[11]
y[4] = mode[12]
print(x,y)
fit = np.polyfit(x,y,1) #make a fit
xfit = np.arange(-10,11)/10.0 #save the fit
line = fit[0]*xfit + fit[1] #plot the line
plt.plot(mode) #compare to imput
plt.plot(line)
plt.show()
return fit #output parameters
这是我放入的数组:
2.863301071014881134e+06
2.460245261639075354e+06
2.093026012088939082e+06
1.760246916946319165e+06
1.459359399934661807e+06
1.186759278075916693e+06
9.379136078178760363e+05
7.075090289232722716e+05
4.896215309857819229e+05
2.779015818236746127e+05
6.577018238002381986e+04
-1.533787985483088996e+05
-3.859754316150106606e+05
-6.380747491954336874e+05
-9.151669400838417932e+05
-1.222001861839911900e+06
-1.562432032544140937e+06
-1.939277663402933627e+06
-2.354219490472638980e+06
-2.807717568478100933e+06
-3.298964879534429871e+06
但有些曲线非常适合......而且我不知道为什么。
这是 12 个拟合的完整数据集,其中只有少数完全拟合,而大约 5 个根本不拟合。
2.863301071014881134e+06,2.460245261639075354e+06,2.093026012088939082e+06,1.760246916946319165e+06,1.459359399934661807e+06,1.186759278075916693e+06,9.379136078178760363e+05,7.075090289232722716e+05,4.896215309857819229e+05,2.779015818236746127e+05,6.577018238002381986e+04,-1.533787985483088996e+05,-3.859754316150106606e+05,-6.380747491954336874e+05,-9.151669400838417932e+05,-1.222001861839911900e+06,-1.562432032544140937e+06,-1.939277663402933627e+06,-2.354219490472638980e+06,-2.807717568478100933e+06,-3.298964879534429871e+06
1.823024837501582457e+06,1.407404888380297925e+06,1.045542366034140810e+06,7.369900890351813287e+05,4.796441426606248133e+05,2.698286365673191613e+05,1.024250849728439935e+05,-2.896099883565749042e+04,-1.317982424403309124e+05,-2.143990311263155891e+05,-2.856664656426848378e+05,-3.548254775850749575e+05,-4.311454552569908556e+05,-5.236618570110450964e+05,-6.409042855782526312e+05,-7.906385211718138307e+05,-9.796293207744800020e+05,-1.213430110346697038e+06,-1.496206498148957733e+06,-1.830595814738985617e+06,-2.217610022593144793e+06
4.798691891424674541e+06,4.335460195711855777e+06,3.862336577153687831e+06,3.381052381723834202e+06,2.893223182883592322e+06,2.400343388215905987e+06,1.903789665149280569e+06,1.404825854079108685e+06,9.046142340220035985e+05,4.042298400829117745e+05,-9.532238749372726306e+04,-5.930878206153763458e+05,-1.088141074660916813e+06,-1.579564367707776371e+06,-2.066426035502505023e+06,-2.547760585996538866e+06,-3.022550547782572918e+06,-3.489710436714207288e+06,-3.948076268974626437e+06,-4.396395672050636262e+06,-4.833326583355414681e+06
3.793703552110599820e+06,3.391412198827212211e+06,2.989782693296195008e+06,2.589578770337372553e+06,2.191246189844559878e+06,1.794929647279789671e+06,1.400503089901715051e+06,1.007606002048938535e+06,6.156892334155119024e+05,2.240665530861769803e+05,-1.680294492848222144e+05,-5.613882603051033802e+05,-9.567615461140368134e+05,-1.354804212866113055e+06,-1.756018122938997578e+06,-2.160700877420521341e+06,-2.568900574604218360e+06,-2.980377833163299598e+06,-3.394578734188971575e+06,-3.810614864194200840e+06,-4.227257391775649041e+06
-2.688736622001025826e+05,-2.891307096734186634e+05,-3.210182462179567665e+05,-3.637685228908676654e+05,-4.161451769185513258e+05,-4.764690694206450135e+05,-5.426589879127629101e+05,-6.122883688792278990e+05,-6.826550662752185017e+05,-7.508627579625872895e+05,-8.139109218074735254e+05,-8.687908509623678401e+05,-9.125844099162584171e+05,-9.425623182375114411e+05,-9.562787566806860268e+05,-9.516588113849731162e+05,-9.270761900481916964e+05,-8.814180572800580412e+05,-8.141346932859588414e+05,-7.252721974752144888e+05,-6.154868653471516445e+05
9.290761216964293271e+04,9.716293103619851172e+04,1.066760295451972634e+05,1.210595604704506695e+05,1.398309263398554176e+05,1.624331190057452768e+05,1.882570907542696223e+05,2.166650927380658686e+05,2.470136447085617110e+05,2.786755592228779569e+05,3.110599570438275114e+05,3.436296166989142075e+05,3.759150219994084910e+05,4.075246579653825611e+05,4.381512495859954506e+05,4.675738988737529144e+05,4.956561688274089247e+05,5.223402258499907330e+05,5.476378741131518036e+05,5.716185480071883649e+05,5.943952403778489679e+05
-1.526902880737665109e+05,-1.735365197676238604e+05,-1.890024515842027031e+05,-1.990524921999722719e+05,-2.037516828224882483e+05,-2.032633730402099900e+05,-1.978446369726238772e+05,-1.878397246057786979e+05,-1.736716232176218182e+05,-1.558319302106322721e+05,-1.348693471926613711e+05,-1.113770128403031267e+05,-8.597902396752825007e+04,-5.931646757646976039e+04,-3.203331006132997572e+04,-4.762504500862210989e+03,2.188737932290835306e+04,4.734455955763859674e+04,7.108546047641383484e+04,9.264432113033020869e+04,1.116216124380915426e+05
2.079714810232995078e+05,2.360356890453444794e+05,2.643386878711422905e+05,2.926172451146300882e+05,3.205867588270269334e+05,3.479488338805735111e+05,3.743995507517913356e+05,3.996394133776463568e+05,4.233835349200218916e+05,4.453720293387128040e+05,4.653802901815772057e+05,4.832283492548773065e+05,4.987890926566505805e+05,5.119948616758547723e+05,5.228420208745803684e+05,5.313934730113642290e+05,5.377785636607399210e+05,5.421904888370856643e+05,5.448816494497396052e+05,5.461558669662652537e+05,5.463592480976451188e+05
-6.004972233628863469e+05,-5.218144770968388766e+05,-4.323520639496566728e+05,-3.328308516886550933e+05,-2.241492617535209283e+05,-1.073722272343654186e+05,1.628341686249244958e+04,1.454689736557258293e+05,2.787269490527026355e+05,4.145172438386715949e+05,5.512458119609234855e+05,6.872943554893778637e+05,8.210504976007230580e+05,9.509374077493352816e+05,1.075441897909167223e+06,1.193140607877797447e+06,1.302723037819108926e+06,1.403011151727671735e+06,1.492975922453127801e+06,1.571748814718301408e+06,1.638630423184413929e+06
-8.224905728125246242e+05,-8.272410185064692050e+05,-8.326893845516629517e+05,-8.388871982868439518e+05,-8.458762596825547516e+05,-8.536853897637501359e+05,-8.623273033962328918e+05,-8.717957186641427688e+05,-8.820629007600517944e+05,-8.930777311472347938e+05,-9.047644510141359642e+05,-9.170221686316537671e+05,-9.297252067997995764e+05,-9.427243347298488952e+05,-9.558488991128550842e+05,-9.689098272587950341e+05,-9.817034558001877740e+05,-9.940160934147448279e+05,-1.005629199419648852e+06,-1.016325006415236276e+06,-1.025892532105713151e+06
-4.424117788771889172e+05,-5.102346394100966863e+05,-5.751149122867453843e+05,-6.363799527015131898e+05,-6.934574586782292463e+05,-7.458898594100442715e+05,-7.933441185955684632e+05,-8.356173786789262667e+05,-8.726374820720185526e+05,-9.044589545214013197e+05,-9.312544687950452790e+05,-9.533022778828768060e+05,-9.709702647911612876e+05,-9.846973581635965966e+05,-9.949731923205442727e+05,-1.002316828812014312e+06,-1.007255601753221359e+06,-1.010304709861830808e+06,-1.011948455100183841e+06,-1.012623895610535983e+06,-1.012707068021281622e+06
3.477817421297905967e+05,3.736243431702046655e+05,3.920268554006759077e+05,4.033072721675941721e+05,4.079090453006611206e+05,4.063751606468805112e+05,3.993197351276362315e+05,3.873984844536441378e+05,3.712793758027623408e+05,3.516147341198949143e+05,3.290160663752942346e+05,3.040326176762795076e+05,2.771345338446269743e+05,2.487012466697013006e+05,2.190154871324780397e+05,1.882628948148782365e+05,1.565372117093461566e+05,1.238505384397571906e+05,9.014778573495894670e+04,5.532475400785356760e+04,1.924863420119788498e+04
最佳答案
我认为你只是得意忘形了,为什么你需要那个 /10
for (in xfit = np.arange(-10,11)/10.0
)?对于您发布的数据集,没有 /10
就完美了:
x = [-2,-1,0,1,2] #Grab a few points around 0 and fit a line
y = mode[8:13]
print(x,y)
fit = np.polyfit(x,y,1) #make a fit
xfit = np.arange(-10,11) #save the fit
line = fit[0]*xfit + fit[1] #plot the line
plt.plot(mode) #compare to imput
plt.plot(line)
关于python - 线性拟合 python 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24171075/
gnuplot 中拟合函数的正确方法是什么 f(x)有下一个表格吗? f(x) = A*exp(x - B*f(x)) 我尝试使用以下方法将其拟合为任何其他函数: fit f(x) "data.txt
(1)首先要建立数据集 ? 1
测量显示一个信号,其形式类似于具有偏移量和因子的平方根函数。如何找到系数并在一个图中绘制原始数据和拟合曲线? require(ggplot2) require(nlmrt) # may be thi
我想将以下函数拟合到我的数据中: f(x) = Offset+Amplitudesin(FrequencyT+Phase), 或根据 Wikipedia : f(x) = C+alphasin(ome
我正在尝试使用与此工具相同的方法在 C# 中拟合 Akima 样条曲线:https://www.mycurvefit.com/share/4ab90a5f-af5e-435e-9ce4-652c95c
问题:开放层适合 map ,只有在添加特征之后(视觉),我该如何避免这种情况? 我在做这个 第 1 步 - 创建特征 var feature = new ol.Feature({...}); 第 2
我有一个数据变量,其中包含以下内容: [Object { score="2.8", word="Blue"}, Object { score="2.8", word="Red"}, Objec
我正在尝试用中等大小的 numpy float 组来填充森林 In [3]: data.shape Out[3]: (401125, 5) [...] forest = forest.fit(data
我想用洛伦兹函数拟合一些数据,但我发现当我使用不同数量级的参数时拟合会出现问题。 这是我的洛伦兹函数: function [ value ] = lorentz( x,x0,gamma,amp )
我有一些数据,我希望对其进行建模,以便能够在与数据相同的范围内获得相对准确的值。 为此,我使用 polyfit 来拟合 6 阶多项式,由于我的 x 轴值,它建议我将其居中并缩放以获得更准确的拟合。 但
我一直在寻找一种方法来使数据符合 beta 二项分布并估计 alpha 和 beta,类似于 VGAM 库中的 vglm 包的方式。我一直无法找到如何在 python 中执行此操作。有一个 scipy
我将 scipy.optimize.minimize ( https://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html ) 函数与
在过去的几天里,我一直在尝试使用 python 绘制圆形数据,方法是构建一个范围从 0 到 2pi 的圆形直方图并拟合 Von Mises 分布。我真正想要实现的是: 具有拟合 Von-Mises 分
我有一个简单的循环,它在每次迭代中都会创建一个 LSTM(具有相同的参数)并将其拟合到相同的数据。问题是迭代过程中需要越来越多的时间。 batch_size = 10 optimizer = opti
我有一个 Python 系列,我想为其直方图拟合密度。问题:是否有一种巧妙的方法可以使用 np.histogram() 中的值来实现此结果? (请参阅下面的更新) 我目前的问题是,我执行的 kde 拟
我有一个简单的 keras 模型(正常套索线性模型),其中输入被移动到单个“神经元”Dense(1, kernel_regularizer=l1(fdr))(input_layer) 但是权重从这个模
我正在尝试解决 Boston Dataset 上的回归问题在random forest regressor的帮助下.我用的是GridSearchCV用于选择最佳超参数。 问题一 我是否应该将 Grid
使用以下函数,可以在输入点 P 上拟合三次样条: def plotCurve(P): pts = np.vstack([P, P[0]]) x, y = pts.T i = np.aran
我有 python 代码可以生成数字 x、y 和 z 的三元组列表。我想使用 scipy curve_fit 来拟合 z= f(x,y)。这是一些无效的代码 A = [(19,20,24), (10,
我正在尝试从 this answer 中复制代码,但是我在这样做时遇到了问题。我正在使用包 VGAM 中的gumbel 发行版和 fitdistrplus . 做的时候出现问题: fit = fi
我是一名优秀的程序员,十分优秀!