親愛なる: 3D の複数のデータ ポイントを含むデータセットがあり、このデータセットに最適な曲線を見つけようとしています。次のように2Dでこれを行うことができます。
import numpy as np
import os
import pandas as pd
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
df_reg1=pd.read_csv('C:\\Users\\wilso\\python\\datasets\\PCD\\df_clean_rail.csv')
df_reg=df_reg1[['x','y','z']]
data = df_reg.values
x, y, z = data[:, 0], data[:, 1], data[:, 2]
def objective(x, a, b, c):
return a * x + b * x**2 + c
popt, _ = curve_fit(objective, x, y)
a, b, c = popt
print('y = %.5f * x + %.5f * x^2 + %.5f' % (a, b, c))
plt.scatter(x, y)
x_line = np.arange(min(x), max(x), 1)
y_line = objective(x_line, a, b, c)
plt.plot(x_line, y_line, '--', color='red')
plt.xlim(-100,10)
plt.ylim(-10,10)
plt.show()
ただし、3D で同じ方法を試すと、トレースバックが発生します。
def objective(x, y, a, b, c):
return a * x + b * y**2 + c
popt, _ = curve_fit(objective, x, y, z)
TypeError: objective() takes 5 positional arguments but 14884 were given
誰か親切にヒントを教えてください。あなたの時間と素晴らしいサポートに感謝します.
心から
ウィルソン