【问题标题】:Predict existing data using scikit learn使用 scikit learn 预测现有数据
【发布时间】:2023-03-09 14:45:01
【问题描述】:

我的数据集如下所示:

年龄地址freetime goout Dalc Walc G1 G2 G3 AverageG 17 U 1 1 3 5 7 7 7 7 15 X 3 2 6 3 5 4 2 3.6666 20 吨 1 5 4 1 3 2 1 2

我正在尝试使用 python 来预测值 AverageG,它是 G1、G2、G3 的平均值。

我知道 AverageG 的值可以通过 G1、G2 和 G3 的平均值来计算,但在我的情况下,它必须使用库 scikit-learn 来预测

【问题讨论】:

  • 嗯,你能不能让它对 G1、G2 和 G3 的值进行多元线性回归?我不知道 scikit 学习,但这可能是你正在寻找的。如果是这样,我相信 Google 搜索可能会为您提供一些实施结果。

标签: python python-3.x machine-learning scikit-learn regression


【解决方案1】:

对于这个玩具示例,您可以使用linear regression

我会给出大致的想法,然后你可以为你的特定数据框翻译它:

from sklearn.linear_model import LinearRegression
import numpy as np

X = np.random.randint(0,10,(1000,3))
y = X.mean(axis=1)

model = LinearRegression()
model.fit(X, y)

new_data = np.array([1,2,3]).reshape(1, -1)
model.predict(new_data)

并且模型正确预测:

array([2.])

【讨论】:

    猜你喜欢
    • 2014-12-14
    • 2015-03-05
    • 2015-02-19
    • 2017-08-13
    • 2015-05-24
    • 2015-12-19
    • 2018-01-09
    • 2015-03-11
    • 2021-11-02
    相关资源
    最近更新 更多