利用python写一段应用佩尔曲线模型进行客运量预测的代码
时间: 2023-06-08 13:05:59 浏览: 90
好的,这里是 Python 代码,使用了 NumPy、Matplotlib 和 Scikit-learn 库来实现佩尔曲线模型进行客运量预测:
```python
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
# 输入数据
X = np.array([55, 60, 65, 70, 75, 80, 85, 90, 95, 100]).reshape((-1, 1))
y = np.array([150, 170, 190, 210, 230, 250, 270, 290, 310, 330])
# 画出原始数据
plt.scatter(X, y)
# 定义佩尔曲线模型
transformer = PolynomialFeatures(degree=2, include_bias=False)
X_ = transformer.fit_transform(X)
model = LinearRegression().fit(X_, y)
# 计算拟合数据
X_test = np.arange(50, 110, 0.1)[:, np.newaxis]
X_test_ = transformer.transform(X_test)
y_pred = model.predict(X_test_)
# 画出拟合曲线
plt.plot(X_test, y_pred)
# 显示图表
plt.show()
```
模型通过给定的训练数据 `X` 和对应的输出值 `y` 进行拟合,使用了 2 次佩尔曲线进行拟合。最终画出了原始数据散点图和佩尔曲线模型的拟合曲线图。可以根据需要修改 X 和 y 的值来测试该模型的预测效果。