如何拟合模型并进行回归预测?

时间:2020-03-20 15:13:27

标签: python dataframe machine-learning scikit-learn regression

我正在构建一个python脚本来预测30天的值。我有一个名为group_by_day的数据框,其列为day和pm25,我想预测其值。我使用scikit train_test_split拆分了数据。我正在使用回归样条训练模型,但是我也不知道如何预测测试数据的值。我已经用火车数据拟合了模型,但是我不知道如何预测值。到目前为止,我设法仅预测火车数据的值,如以下代码所示:

transformed_x1 = dmatrix(
        "bs(group_by_df['day'][:len(X_train)], knots=(percentile_25,percentile_50,percentile_75), degree=5, include_intercept=False)",
        {"group_by_df['day'][:len(X_train)]": group_by_df['day'][:len(X_train)]}, return_type='dataframe')

    fit_spline = sm.GLM(group_by_df['pm25'][:len(X_train)], transformed_x1).fit()
    pred_spline = fit_spline.predict(transformed_x1)

0 个答案:

没有答案