40
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()

Can anyone please help me I am facing a error as soon as I put X = features_df.as_matrix() y = df['Price'].as_matrix() and I am learning Machine Learning with a book called Machine Learning with python by oliver... Any Help is highly appreciated Thankyou

martineau
  • 119,623
  • 25
  • 170
  • 301
Laxman Srivastava
  • 401
  • 1
  • 4
  • 3

4 Answers4

73

df.as_matrix() was deprecated after version 0.23.0. Use df.values instead.

Follow this link for additional information.

Alex Metsai
  • 1,837
  • 5
  • 12
  • 24
TUSHAR
  • 863
  • 6
  • 9
17

Dataframe depricated a lot of attributes such as .ix

Here you need this command:

y = df['Price'].values
Code42
  • 2,292
  • 1
  • 17
  • 22
14

Replacing .as_matrix() with .values() also resulted in an error, but replacing it with .to_numpy() worked perfectly

Convert the DataFrame to a NumPy array.

New in version 0.24.0.

Valdas
  • 198
  • 1
  • 7
5

As of Pandas 1.0 use .to_numpy() other ways are deprecated according to the docs

juan Isaza
  • 3,646
  • 3
  • 31
  • 37