Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'DataFrame' object has no attribute 'as_matrix

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

like image 476
Laxman Srivastava Avatar asked Apr 08 '20 13:04

Laxman Srivastava


People also ask

What is Dataframe object has no attribute as_matrix error in pandas?

Attributeerror: dataframe object has no attribute as_matrix error occurs because as_matrix () function is deprecated in pandas latest version. Mostly when we try to convert pandas dataframe to NumPy array with as_matrix () function in the recent version we get this error.

Which object has no attribute ‘as_matrix’?

AttributeError: 'DataFrame' object has no attribute 'as_matrix' def plot_fruit_knn (X, y, n_neighbors, weights): X_mat = X [ ['height', 'width']].as_matrix () y_mat = y.as_matrix ()

What happened to as_matrix in Dataframe?

df.as_matrix () was deprecated after version 0.23.0. Use df.values instead. Follow this link for additional information. Show activity on this post. Dataframe depricated a lot of attributes such as .ix

How to convert a Dataframe to a NumPy array?

Dataframe depricated a lot of attributes such as .ix Show activity on this post. 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.


2 Answers

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

Follow this link for additional information.

like image 150
TUSHAR Avatar answered Oct 01 '22 18:10

TUSHAR


Dataframe depricated a lot of attributes such as .ix

Here you need this command:

y = df['Price'].values 
like image 26
Dr_Hope Avatar answered Oct 01 '22 20:10

Dr_Hope