AttributeError: 'numpy.ndarray' object has no attribute 'target
AttributeError: 'numpy.ndarray' object has no attribute 'target
我在执行 grid.fit()
命令时收到错误 "AttributeError: 'numpy.ndarray' object has no attribute 'target'"。我不确定这意味着什么以及如何解决它。有人可以建议吗?
#Grid Search Parameter Tuning
import numpy as np
from sklearn import datasets
from sklearn.linear_model import Ridge
from sklearn.model_selection import GridSearchCV
# datasets
dataset = np.random.rand(1000,2)
#Ridge regression
alphas = np.array([1,0.1,0.01,0.001,0.0001,0])
model = Ridge()
grid = GridSearchCV(estimator=model, param_grid=dict(alpha=alphas))
grid.fit(dataset.data, dataset.target)
您已将创建的随机数组作为您的数据集,您正在传递适合的数据集,但该数据没有目标,您需要定义另一个定义标签的数组。
x = np.random.rand(1000,2)
y3 = np.concatenate((np.zeros(500),np.ones(500)))
random = np.random.permutation(1000)
y = y3[random]
我在执行 grid.fit()
命令时收到错误 "AttributeError: 'numpy.ndarray' object has no attribute 'target'"。我不确定这意味着什么以及如何解决它。有人可以建议吗?
#Grid Search Parameter Tuning
import numpy as np
from sklearn import datasets
from sklearn.linear_model import Ridge
from sklearn.model_selection import GridSearchCV
# datasets
dataset = np.random.rand(1000,2)
#Ridge regression
alphas = np.array([1,0.1,0.01,0.001,0.0001,0])
model = Ridge()
grid = GridSearchCV(estimator=model, param_grid=dict(alpha=alphas))
grid.fit(dataset.data, dataset.target)
您已将创建的随机数组作为您的数据集,您正在传递适合的数据集,但该数据没有目标,您需要定义另一个定义标签的数组。
x = np.random.rand(1000,2)
y3 = np.concatenate((np.zeros(500),np.ones(500)))
random = np.random.permutation(1000)
y = y3[random]