使用小数据集进行回归

问题描述 投票:0回答:2

我们检查了一个据说用于破解的软件。我们发现工作时间显着取决于输入长度N,特别是当N大于10-15时。在我们的测试中,我们修复了以下工作时间。

N = 2 - 16.38 seconds 
N = 5 - 16.38 seconds 
N = 10 - 16.44 seconds 
N = 15 - 18.39 seconds 
N = 20 - 64.22 seconds 
N = 30 - 65774.62 seconds

任务:查找以下三种情况的程序工作时间 - N = 25,N = 40和N = 50。

我试图进行多项式回归,但预测值从2,3度变化,......

# Importing the libraries 
import numpy as np 
import matplotlib.pyplot as plt 

# Importing the dataset 
X = np.array([[2],[5],[10],[15],[20],[30]])
X_predict = np.array([[25], [40], [50]])
y = np.array([[16.38],[16.38],[16.44],[18.39],[64.22],[65774.62]])
#y = np.array([[16.38/60],[16.38/60],[16.44/60],[18.39/60],[64.22/60],[65774.62/60]])


# Fitting Polynomial Regression to the dataset 
from sklearn.preprocessing import PolynomialFeatures 

poly = PolynomialFeatures(degree = 11) 
X_poly = poly.fit_transform(X) 

poly.fit(X_poly, y) 
lin2 = LinearRegression() 
lin2.fit(X_poly, y) 

# Visualising the Polynomial Regression results 
plt.scatter(X, y, color = 'blue') 

plt.plot(X, lin2.predict(poly.fit_transform(X)), color = 'red') 
plt.title('Polynomial Regression') 


plt.show() 

# Predicting a new result with Polynomial Regression 
lin2.predict(poly.fit_transform(X_predict))

对于2级,结果是

array([[ 32067.76147835],
       [150765.87808383],
       [274174.84800471]])

对于5级,结果是

array([[  10934.83739791],
       [ 621503.86217946],
       [2821409.3915933 ]])
python regression non-linear-regression
2个回答
1
投票

在方程式搜索之后,我能够将数据拟合到等式“seconds = a * exp(b * N)+ Offset”,其中拟合参数a = 2.5066753490350954E-05,b = 7.2292352155213369E-01,Offset = 1.6562196782144639E + 01给出RMSE = 0.2542,R平方= 0.99999。这种数据和方程的组合对初始参数估计非常敏感。如您所见,它应该在数据范围内以高精度进行插值。由于方程式很简单,因此很可能在数据范围之外进行推断。据我了解您的描述,如果使用不同的计算机硬件或者如果并行化了破解算法,则此解决方案将不符合这些更改。

enter image description here


1
投票

由于这个程序用于破解,它可能会使用某种强力导致指数性能时间,所以找到解决方案要好得多

y = a + b * c ^ n

例如:

16.38 + 2.01 ^ n / 20000

您可以尝试在log(time)中预测time而不是LinearRegression

© www.soinside.com 2019 - 2024. All rights reserved.