數(shù)據(jù):房?jī)r(jià)預(yù)測(cè)
繪圖方式:二維 繪圖庫(kù):seaborn
%matplotlib inline
import pandas as pd
import seaborn as sns
#import matplotlib.pyplot as pl
sns.set(context= "notebook", style= "whitegrid", palette="dark")
df0 = pd.read_csv('data0.csv', names = ['square', 'price'])
sns.lmplot('square', 'price', df0, height = 6, fit_reg = True)
繪圖方式:三維 繪圖庫(kù):matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
df1 = pd.read_csv('data1.csv', names = ['square', 'bedrooms', 'price'])
df1.head()
%matplotlib inline
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.set_xlabel('square')
ax.set_ylabel('bedrooms')
ax.set_zlabel('price')
#繪制3D散點(diǎn)圖
ax.scatter3D(df1['square'], df1['bedrooms'], df1['price'], c = df1['price'], cmap ="Greens")
def normalize_feature(df):
return df.apply(lambda column: (column - column.mean()) / column.std())
df = normalize_feature(df1)
ax = plt.axes(projection = '3d')
ax.set_xlabel('square')
ax.set_ylabel('bedrooms')
ax.set_zlabel('price')
ax.scatter3D(df['square'], df['bedrooms'], df['price'], c = df['price'], cmap = 'Reds')
import numpy as np
ones = pd.DataFrame({'ones': np.ones(len(df))})#ones是n行1列的數(shù)據(jù)框签夭,表示x0恒為1
df = pd.concat([ones, df], axis = 1) #根據(jù)列合并數(shù)據(jù)
#df.head()