如果我的数据帧没有NAN,为什么lasso模型没有运行?

2024-06-16 09:47:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在运行一个模型。它运行得非常完美,我不知道我做了什么,现在没有运行。小背景我制作了一个数据框,并为列中的所有NaN添加了值。然后创建我的预测器和目标,运行套索模型。当我运行lasso模型时,它给了我一个输入值error contains NaN、infinity或一个对dtype来说太大的值('float64')。 此外,我还通过运行final_data.isna().sum()仔细检查了我的列是否没有NaN值,并发现所有列都返回了0

def build_and_fit_lasso_model(X, y):
    """Creates and returns a LASSO model that is fitted to the values of the
    given predictor and target X, and y.
    """
    model = LassoLarsCV(cv=10, precompute = False)  
    model = model.fit(X_train.values, y_train.values)
    return model # implement this function

然后当我运行时,这会给我错误

lasso_model = build_and_fit_lasso_model(X_train, y_train)
lasso_model

Tags: andthe数据模型build目标modeltrain