如何在XGBoost回归器中找到模型系数?

时间:2019-07-31 12:02:37

标签: regression xgboost

在XGBoost回归中预测价格,如何获取系数,模型的截距?像我们在Statsmodel中获得线性回归一样,如何获取模型摘要? 参见下面的代码

import { Popover } from '@material-ui/core/'
import classnames from 'classnames'
import React from 'react'
import { withStyles } from '../styles/'
import { popoverStyles } from './styles'


const MYPopover = withStyles(popoverStyles)(class extends React.Component {

    static displayName = 'MYPopover'

    static propTypes = Popover.propTypes

    render() {

        const { props } = this

        return (
            <Popover {...{
                ...props,
                className: classnames('my-popover', props.className)
            }} />
        )
    }
})

export default MYPopover
from xgboost import XGBRegressor
# fit model no training data
model = XGBRegressor()
model.fit(X_train, y_train)
# make predictions for test data
y_pred = model.predict(X_test)

这是我建立模型并尝试获得这样的系数的方法:

print("R^2: {}".format(model.score(X_test, y_test)))
rmse = np.sqrt(mean_squared_error(y_test, y_pred))
print("Root Mean Squared Error: {}".format(rmse))
#print the intercept
print(model.intercept_)
AttributeError: Intercept (bias) is not defined for Booster type gbtree
print(model.coef_)

有人可以帮我解决这个问题吗?谢谢。

1 个答案:

答案 0 :(得分:1)

仅当选择线性模型作为基础学习器(booster = gblinear)时才定义系数。没有为其他基础学习者类型(例如树学习者(booster = gbtree))定义此定义。默认值为booster = gbtree