Advertisement
EXTREMEXPLOIT

Regresión Lineal (Multiples Variables)

Mar 14th, 2020
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. from mpl_toolkits.mplot3d import Axes3D
  3. from matplotlib import cm, style
  4. import numpy as np
  5. import pandas as pd
  6.  
  7. style.use('dark_background')
  8. DATASET = pd.read_csv('CarPrice.csv', sep=',')
  9. X1, X2, Y = DATASET['wheelbase'], DATASET['horsepower'], DATASET['price']
  10. X = np.transpose([np.ones(len(X1)), X1, X2])
  11. Y = np.transpose(Y)
  12. B = np.matmul(np.linalg.inv(np.matmul(np.transpose(X), X)), np.matmul(np.transpose(X), Y))
  13.  
  14. x, y = np.meshgrid(np.linspace(min(X1), max(X1), 10), np.linspace(min(X2), max(X2), 10))
  15. Z = B[0] + B[1]*x + B[2]*y
  16.  
  17.  
  18. fig = plt.figure()
  19. ax = plt.axes(projection='3d')
  20. ax.scatter3D(X1, X2, Y, color='red')
  21. ax.plot_surface(x, y, Z, alpha=0.75, cmap=cm.Blues)
  22. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement