python - 数据集不可调用问题
问题描述
我试图估算 NaN 值,但首先我想检查计算该值的最佳方法。我是使用这种方法的新手,所以我想使用我发现的代码来处理不同的回归量并选择最好的。原代码是这样的:
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 是他的数据集。
因此,当我尝试将此代码改编为我的案例时,我编写了以下代码:
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
我总是遇到同样的错误:
AttributeError: 'numpy.ndarray' object is not callable
在我使用我的 DF 作为 csv (df.csv) 之前,错误是一样的
AttributeError: 'Dataset' object is not callable
完整的错误是这样的:
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
而且我不知道如何解决两个错误中的一个以消失
我希望能很好地解释我的问题,因为我的英语不是很好
解决方案
推荐阅读
- layout - 约束布局缺少属性(根本没有属性)
- r - 如果需要,R Shiny Refresh 全局变量
- python - 在 Python 中使用随机 x,y 坐标绘制阿基米德螺线
- python - 如何判断程序是否打开
- mysql - 更新时mysql死锁
- javascript - 如何正确地将数组传递给 JSON
- javascript - 循环遍历包含布尔值的对象
- ssh - CLion WSL ssh 会话与 x11
- ruby-on-rails - Rails 无法执行 db:migrate,数据库被锁定并且没有模式迁移表
- ruby-on-rails - Rails hide Model field by default to every query