【输入形式】

import numpy as np

# 已知数据
data = np.array([
    [0.5, 2.0, 6.0],
    [5.0, 6.0, 15.0],
    [3.2, 4.0, 11.4],
    [7.8, 11.0, 20.6],
])

# 待预测数据
x = np.array([11, 8])

【输出形式】

import numpy as np
from sklearn.linear_model import LinearRegression

# 已知数据
data = np.array([
    [0.5, 2.0, 6.0],
    [5.0, 6.0, 15.0],
    [3.2, 4.0, 11.4],
    [7.8, 11.0, 20.6],
])

# 待预测数据
x = np.array([11, 8])

# 将已知数据转化为二维数组
X = data[:, :-1]
y = data[:, -1]

# 线性回归模型
lr = LinearRegression()

# 拟合模型
lr.fit(X, y)

# 预测
y_pred = lr.predict([x])

print(y_pred)

输出结果为:

[27.]
``
写一个python代码:多元线性回归 把已知数据变成二维数组如样例输出所示。用线性回归预测x1x2=118时的y值。【输入形式】【输出形式】 x1 x2 ya1 05 20 60a2 50 60 150a3 32 40 114a4 78 110 20627

原文地址: https://www.cveoy.top/t/topic/hnLG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录