Home > Software engineering >  'numpy.ndarray' object is not callable, code is as follows
'numpy.ndarray' object is not callable, code is as follows

Time:06-07

When I was working on a machine learning project on housing price prediction, I encountered the following problem,it shows:

'numpy.ndarray' object is not callable.

The error code is as follows:

X = df.values(['bedrooms', 'bathrooms', 'sqft_living',\
       'sqft_lot', 'floors', 'waterfront', 'view', 'condition', 'grade',\
       'sqft_above', 'sqft_basement', 'yr_built', 'yr_renovated', 'zipcode',\
       'lat', 'long', 'sqft_living15', 'sqft_lot15'])
y = df['price']
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=10)

CodePudding user response:

You can use df[[]] structure behalf of df.values

import pandas as pd
file_name='https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/DA0101EN/coursera/project/kc_house_data_NaN.csv'
df=pd.read_csv(file_name)

X = df[['bedrooms', 'bathrooms', 'sqft_living',\
       'sqft_lot', 'floors', 'waterfront', 'view', 'condition', 'grade',\
       'sqft_above', 'sqft_basement', 'yr_built', 'yr_renovated', 'zipcode',\
       'lat', 'long', 'sqft_living15', 'sqft_lot15']]
y = df[['price']]
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=10)
  • Related