小数据集回归

Regression with a small dataset

我们检查了一个据称用于破解的软件。我们发现工作时间在很大程度上取决于输入长度 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

任务: of 查找以下三种情况的程序工作时间 - 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 ]])

由于这个程序是用来破解的,它可能会使用某种暴力破解,导致性能时间呈指数增长,所以最好找到解决方案

y = a + b * c^n

例如:

16.38 + 2.01^n / 20000

您可以尝试在 LinearRegression

中预测 log(time) 而不是 time

方程搜索后,我能够将数据拟合到方程 "seconds = a * exp(b * N) + Offset" 中,拟合参数 a = 2.5066753490350954E-05,b = 7.2292352155213369E-01,偏移量 = 1.6562196782144639E+01,给出 RMSE = 0.2542 和 R 平方 = 0.99999。这种数据和方程式的组合对初始参数估计极为敏感。如您所见,它应该在数据范围内以高精度进行插值。由于方程很简单,它很可能会很好地推断出数据范围之外。据我了解你的描述,如果使用不同的计算机硬件或如果破解算法是并行的,那么这个解决方案将无法匹配这些变化。