【问题标题】:Sales Prediction error on catboost regression/CatBoostRegressorcatboost 回归/CatBoostRegressor 上的销售预测错误
【发布时间】:2021-02-18 16:27:13
【问题描述】:
d = {'customer':['A','B','C','A'],'season':[1,2,3,4],
'cat1': ['BAGS','TSHIRT','DRESS','BELT'],
'cat2': ['high','low','high','medium'],'sale': [10,20,15,50]}
df = pd.DataFrame(data=d)
df

第 5 季的期望输出

d = {'customer':['A','B','C','A'],'season': [5,5,5,5],
'cat1': ['BAGS','TSHIRT','DRESS','BELT'],
'cat2': ['high','low','high','medium'],'sale': [?,?,?,?]}
df = pd.DataFrame(data=d)
df

我试过了

df=df.groupby(['customer','season','cat1','cat2'])['Sales'].sum().sort_values(ascending=False).reset_index()
from sklearn.model_selection import train_test_split
X=df[['customer','season','cat1','cat2']]
y=df[['Sales']]

X.season=X.season.astype(float)
X_train, X_test, y_train, y_test = train_test_split(X,y,train_size = 0.90, random_state =42)
X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, train_size = 0.85, random_state =42)
categorical_features_indices = np.where(X.dtypes != np.float)[0]
import catboost
from catboost import MetricVisualizer, Pool, CatBoostRegressor, cv
train_pool = Pool(data=X_train, label=y_train, cat_features=categorical_features_indices)
val_pool = Pool(data=X_val, label=y_val, cat_features=categorical_features_indices)
test_pool = Pool(data=X_test, label=y_test, cat_features=categorical_features_indices)


params = {
   'iterations':900,
   'loss_function': 'RMSE',
   'learning_rate': 0.0109, #1 0.102,
   'depth': 6,
   'l2_leaf_reg': 6,
   
   'border_count': 7,
   'thread_count': 7,
   
   'bagging_temperature': 2,
   'random_strength': 2.23,
   'colsample_bylevel': 0.85,
   
   'custom_metric': ['MAPE', 'R2'], 
   'eval_metric': 'R2', 
   'random_seed': 41,
   
   'max_ctr_complexity': 2,
   'logging_level': 'Silent',
   'use_best_model':False # Takes
}


reg_model = CatBoostRegressor(**params)
reg_model.fit(train_pool, eval_set=val_pool, plot=True, verbose=100)



X['season']=5
X['Predict_sales']=reg_model.predict(X)

上面的代码没有报错。

我的问题是:如果输入 5、6、7、8,我的预测值不会改变,但是季节是一个连续值。我做错了什么以及如何预测第 6、7、8 季等等。

【问题讨论】:

标签: regression data-science prediction catboost catboostregressor


【解决方案1】:

catboost 是一个基于树的模型。回归树(以及决策树)对特征空间进行分区,每个分区产生相同的值。由于训练数据中没有出现第 5、6、7 或 8 季,因此它应该全部落在同一个分区中,因此产生完全相同的值。
您可能需要选择另一种模型类型(例如线性回归)。您期望季节和销售之间有什么样的关系?预测你在训练数据中没有看到的东西总是很困难的(除非有类似线性关系的东西)

【讨论】:

    猜你喜欢
    • 2018-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-05
    • 2018-06-11
    • 1970-01-01
    • 2020-03-15
    相关资源
    最近更新 更多