Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- from mpl_toolkits.mplot3d import Axes3D
- from matplotlib import cm, style
- import numpy as np
- import pandas as pd
- style.use('dark_background')
- DATASET = pd.read_csv('CarPrice.csv', sep=',')
- X1, X2, Y = DATASET['wheelbase'], DATASET['horsepower'], DATASET['price']
- X = np.transpose([np.ones(len(X1)), X1, X2])
- Y = np.transpose(Y)
- B = np.matmul(np.linalg.inv(np.matmul(np.transpose(X), X)), np.matmul(np.transpose(X), Y))
- x, y = np.meshgrid(np.linspace(min(X1), max(X1), 10), np.linspace(min(X2), max(X2), 10))
- Z = B[0] + B[1]*x + B[2]*y
- fig = plt.figure()
- ax = plt.axes(projection='3d')
- ax.scatter3D(X1, X2, Y, color='red')
- ax.plot_surface(x, y, Z, alpha=0.75, cmap=cm.Blues)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement