我不断收到以下警告:
[17:04:03] WARNING: src/objective/regression_obj.cu:152: reg:linear is now deprecated in favor of reg:squarederror.
我尝试过的事情:
1)
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
2)#!/usr/bin/env python -W ignore::DeprecationWarning
3)python -W ignore foo.py
4)
%env PYTHONWARNINGS="ignore"
%env PYTHONDEPRECATEDWARNINGS="ignore"
重新创建错误的代码(如下): 这只是一个例子,如果您在jupternotebook上运行此命令,则会给出警告,然后出现许多错误。忽略错误,因为我没有为机器学习模型输入正确的数据,在我的实际代码中没有遇到这些错误。但是只是警告
import pandas as pd
import numpy as np
import datetime
todays_date = datetime.datetime.now().date()
index = pd.date_range(todays_date-datetime.timedelta(10), periods=10, freq='D')
columns = ['A','B', 'C']
df = pd.DataFrame(index = index, columns=columns)
df = df.fillna(0)
x = df['A']
y = df['B']
from sklearn.model_selection import train_test_split
from xgboost import XGBRegressor
x_train, x_test, y_train, y_test = train_test_split(x,y,test_size=0.2,random_state=0)
regressor = XGBRegressor(learning_rate=0.1,alpha=0,max_depth=6,sample=0.5,min_sample=10,n_estimators=500)
regressor.fit(x_train,y_train)
#regressor.predict(x_test)
enter code here
enter code here
答案 0 :(得分:0)
升级库没有帮助。我更改了文件[path \ Python \ Lib \ site-packages \ xgboost \]中的def init 的属性objective =“ =”:squarederror“的默认值” =“ reg:linear”的默认值sklearn.py]。