0

Im trying to impute NaN values but,first i want to check the best method to calculate this values. Im new using this methods, so im want to use a code i found to capare the differents regressors and choose the best. The original code is this:

from sklearn.experimental import enable_iterative_imputer  # noqa
from sklearn.datasets import fetch_california_housing
from sklearn.impute import SimpleImputer
from sklearn.impute import IterativeImputer
from sklearn.linear_model import BayesianRidge
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import ExtraTreesRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.pipeline import make_pipeline
from sklearn.model_selection import cross_val_score

N_SPLITS = 5

rng = np.random.RandomState(0)

X_full, y_full = fetch_california_housing(return_X_y=True)
# ~2k samples is enough for the purpose of the example.
Remove the following two lines for a slower run with different error bars.
X_full = X_full[::10]
y_full = y_full[::10]
n_samples, n_features = X_full.shape

fetch_california_housing is his Dataset.

So, when i try to adapt this code to my case i wrote this code:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd


from numpy import genfromtxt
data = genfromtxt('documents/datasets/df.csv', delimiter=',')
features = data[:, :2]
targets = data[:, 2]

N_SPLITS = 5
rng = np.random.RandomState(0)
X_full, y_full = data(return_X_y= True)
# ~2k samples is enough for the purpose of the example.
# Remove the following two lines for a slower run with different error bars.
X_full = X_full[::10]
y_full = y_full[::10]
n_samples, n_features = X_full.shape

I always get the same error:

AttributeError: 'numpy.ndarray' object is not callable

and before I used my DF as csv (df.csv) the error is the same

AttributeError: 'Dataset' object is not callable

the complete error is this:

ypeError Traceback (most recent call last) <ipython-input-8-3b63ca34361e>    in <module> 
3 rng = np.random.RandomState(0) 4 
----> 5 X_full, y_full = df(return_X_y=True) 
6 # ~2k samples is enough for the purpose of the example. 
7 # Remove the following two lines for a slower run with different error     bars. 
TypeError: 'DataFrame' object is not callable 

and i dont know how to solve one of both error to go away

I hope to explain well my problem cause my english is not very good

  • Please refer the rows your errors are pointing to. But as far as I can tell, I think, that your "data" object is an ndarray and not a function as "fetch_california_housing" which returns a 'sklearn.utils.Bunch' which one can see here: https://scikit-learn.org/stable/modules/generated/sklearn.datasets.fetch_california_housing.html – sascha10000 Sep 15 '20 at 11:41
  • this is the line, sorry: X_full, y_full = data(return_X_y= True) – Beatriz SR Sep 15 '20 at 11:45
  • Please modify your question accordingly, as it is hardly readable. There is a reference to row 5 which does not fit to the code you provided (there stand 'df(....)') and in your code snippet it is called 'data'. As it is called df I may assume that the type is a dataframe and your error just states that it is not callable meaning df-->()<--- this is not possible. Please check out python syntax what a callabe object is, than you'll understand. On the other hand it is not clear where 'df' or 'data' or whatever you call it is comming from, your example seems incomplete. – sascha10000 Sep 15 '20 at 11:49
  • i posted all my code – Beatriz SR Sep 15 '20 at 14:44
  • Do you understand this error? You try to use data the same way as the person in the exmaple did. This won't work because your datatype of 'data' is ndarray (as genfromtxt is returning that). This datatype is not callable. If you are a beginner to python or even coding please research the meaning of that error. It may be advanced python but is kind of a basic concept https://stackoverflow.com/questions/111234/what-is-a-callable?rq=1. Your error is more than obvious sorry it's not meant to be discriminating. – sascha10000 Sep 15 '20 at 15:05
  • Try this: Remove the row X_full, y_full = data(return_X_y= True) Rename: features to X_full and targets to y_full. I don't think that the types will be the same but that is basically what you need to accomplish if you want your code to work. He gets his data from fetch_california_housing which yields a different datatype you are using and therefore you don't have the same functions. The only help I can offer you is to read the documentation of the functions you are using and he is https://scikit-learn.org/stable/modules/generated/sklearn.datasets.fetch_california_housing.html – sascha10000 Sep 15 '20 at 15:06

0 Answers0