Как построить трехмерную множественную линейную регрессию с двумя функциями, используя matplotlib? - PullRequest
1 голос
/ 16 февраля 2020

Мне нужно построить трехмерный график с несколькими линейными регрессиями с двумя функциями в matplotlib. Как я могу это сделать?

это мой код:

import pandas
from sklearn import linear_model

df = pandas.read_csv("cars.csv")

X = df[['Weight', 'Volume']]
y = df['CO2']

regr = linear_model.LinearRegression()

predictedCO2 = regr.predict([scaled[0]])
print(predictedCO2)

1 Ответ

0 голосов
/ 17 февраля 2020

Итак, вы хотите построить трехмерный график результатов вашей регрессионной модели. На вашем трехмерном графике для каждой точки у вас есть (x, y, z) = (вес, объем, прогнозируемый CO2).

Теперь вы можете построить ее с помощью:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import random

# dummy variables for demonstration
x = [random.random()*100 for _ in range(100)]
y = [random.random()*100 for _ in range(100)]
z = [random.random()*100 or _ in range(100)]

# build the figure instance
fig = plt.figure(figsize=(10,8))
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x, y, z, c='blue', marker='o')

# set your labels
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

plt.show()

Это будет дать вам сюжет, как это:

enter image description here

...