开始使用免费开始使用

建模的动机:插值

建模的一个常见用途是进行插值,用于确定落在观测数据点"内部"或"两点之间"的值。在本练习中,您将为自变量 times 的某个取值做出预测,该取值位于两次公路旅行测量之间;因变量 distances 表示对应经过时间所行驶的距离。

context figure

本练习是课程的一部分

Python 线性建模入门

查看课程

练习说明

  • 查看预定义的数据数组 timesdistances,以及预加载的图。
  • 基于您的粗略观察,估计在 elapse_time = 2.5 小时时相对于起点的 distance_traveled
  • 将您的答案赋给 distance_traveled

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Compute the total change in distance and change in time
total_distance = ____[-1] - ____[0]
total_time = ____[-1] - ____[0]

# Estimate the slope of the data from the ratio of the changes
average_speed = total_distance / total_time

# Predict the distance traveled for a time not measured
elapse_time = 2.5
distance_traveled = average_speed * elapse_time
print("The distance traveled is {}".format(distance_traveled))
编辑并运行代码