gpt4 book ai didi

python - 为什么需要 "prediction space"?

转载 作者:行者123 更新时间:2023-11-30 08:58:00 25 4
gpt4 key购买 nike

这是一个关于使用回归探索 Gapminder 数据进行预测的老问题。他们使用“预测空间”来计算预测。

Q1。我为什么要创建“预测空间”?它有什么用?

第二季度。 “预测空间”上计算预测的关系?

import numpy as np
import pandas as pd

# Read the CSV file into a DataFrame: df
df = pd.read_csv('gapminder.csv')

The data seems like this;

Country,Year,life,population,income,region

Afghanistan,1800,28.211,3280000,603.0,South Asia

Slovak Republic,1960,70.47800000000001,4137224,8693.0,Europe & Central Asia

# Create arrays for features and target variable
y = df.life.values
X = df.fertility.values

# Reshape X and y
y = y.reshape(-1,1)
X = X.reshape(-1,1)

# Create the regressor: reg
reg = LinearRegression()

# Create the prediction space
prediction_space = np.linspace(min(X_fertility), max(X_fertility)).reshape(-1,1)

# Fit the model to the data
reg.fit(X_fertility, y)

# Compute predictions over the prediction space: y_pred
y_pred = reg.predict(prediction_space)

最佳答案

我相信您正在学习 DataCamp 的类(class)

我也偶然发现了这一点,答案是 prediction_spacey_pred 用于构造图中的直线

注意:对于那些正在阅读本文但不明白我在说什么的人,代码片段实际上缺少图形绘制代码

# Plot regression line
plt.plot(prediction_space, y_pred, color='black', linewidth=3)
plt.show()

关于python - 为什么需要 "prediction space"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52254126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com