【发布时间】:2019-09-04 03:00:11
【问题描述】:
我们检查了一个据称用于破解的软件。我们发现工作时间很大程度上取决于输入长度 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