为什么“的预测空间”的需要?

问题描述 投票:1回答:1

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

Q1。为什么我应该创造“的预测空间”?有什么用呢?

Q2。在“预测空间”的计算预测的关系?

import numpy as np
import pandas as pd

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

这些数据似乎是这一点;

国家,年份,生活,人口,收入,区域

阿富汗,1800,28.211,3280000,603.0,南亚

斯洛伐克共和国,1960,70.47800000000001,4137224,8693.0,欧洲和中亚

# 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)
python machine-learning scikit-learn linear-regression
1个回答
1
投票

我相信你是从DataCamp服用一个疗程

我在此绊倒过了,答案是prediction_spacey_pred被用来构建直线图

注:对于那些谁读这篇文章,不明白我在说什么,该代码片段实际上是缺少图表描绘代码

# Plot regression line
plt.plot(prediction_space, y_pred, color='black', linewidth=3)
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.