Lax*_*ava 23 python dataframe pandas
import pandas as pd
from sklearn.model_selection import train_test_split
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn import ensemble
from sklearn.metrics import mean_absolute_error
from joblib import *
df = pd.read_csv('~/Downloads/Melbourne_housing_FULL.csv')
df.head(n=5)
del df['Address']
del df['Method']
del df['SellerG']
del df['Date']
del df['Postcode']
del df['Lattitude']
del df['Longtitude']
del df['Regionname']
del df['Propertycount']
df.dropna(axis=0, how='any', thresh=None, subset=None, inplace=True)
features_df = pd.get_dummies(df, columns=['Suburb', 'CouncilArea', 'Type'])
X = features_df.as_matrix()
y = df['Price'].as_matrix()
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我我在输入 X = features_df.as_matrix() y = df['Price'].as_matrix() 时遇到错误,我正在用 Oliver 的名为 Machine Learning with python 的书学习机器学习...任何帮助都非常感谢谢谢
Dr_*_*ope 12
Dataframe 贬低了很多属性,例如 .ix
在这里你需要这个命令:
y = df['Price'].values
Run Code Online (Sandbox Code Playgroud)
小智 5
替换.as_matrix()为.values()也导致错误,但替换为.to_numpy()完美工作
将 DataFrame 转换为 NumPy 数组。
0.24.0 版中的新功能。
| 归档时间: |
|
| 查看次数: |
28754 次 |
| 最近记录: |