i’m currently doing the machine learning exercise:
MULTIPLE LINEAR REGRESSION
Introduction to Multiple Linear Regression
with the following code:
import codecademylib3_seaborn import matplotlib.pyplot as plt import numpy as np import pandas as pd from mpl_toolkits.mplot3d import Axes3D from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split streeteasy = pd.read_csv("https://raw.githubusercontent.com/sonnynomnom/Codecademy-Machine-Learning-Fundamentals/master/StreetEasy/manhattan.csv") df = pd.DataFrame(streeteasy) x = df[['size_sqft','building_age_yrs']] y = df[['rent']] x_train, x_test, y_train, y_test = train_test_split(x, y, train_size = 0.8, test_size = 0.2, random_state=6) ols = LinearRegression() ols.fit(x_train, y_train) # Plot the figure fig = plt.figure(1, figsize=(6, 4)) plt.clf() elev = 43.5 azim = -110 ax = Axes3D(fig, elev=elev, azim=azim) ax.scatter(x_train[['size_sqft']], x_train[['building_age_yrs']], y_train, c='k', marker='+') ax.plot_surface(np.array([[0, 0], [4500, 4500]]), np.array([[0, 140], [0, 140]]), ols.predict(np.array([[0, 0, 4500, 4500], [0, 140, 0, 140]]).T).reshape((2, 2)), alpha=.7) ax.set_xlabel('Size (ft$^2$)') ax.set_ylabel('Building Age (Years)') ax.set_zlabel('Rent ($)') ax.w_xaxis.set_ticklabels() ax.w_yaxis.set_ticklabels() ax.w_zaxis.set_ticklabels() # Add the code below: plt.show()
I redue all the code in VS code, with that it works for me better to connect the content and play around a bit.
Unfortunately in VS code i receive the following message:
UserWarning: X does not have valid feature names, but LinearRegression was fitted with feature names
does someone has an idea how to solve that?