我有一个包含许多列的数据集:
有4个变量用于预测: -季节(总和、aut、win、spr) -特快装运(真、假) -运输距离(以公里为单位) -首次客户(对、错)
这4个变量用于计算装运价格,规则如下:, 对于每个季节,都有一个使用上述变量的单独模型
我使用了一种方法,将True转换为1,将False转换为0 对于2个布尔列 我还将季节转换为整数表示(1,2,3,4)
问题是我的预测非常不准确,下面是我使用的代码
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
modeling = data.loc[:,["shipping_distance","season_int","new_cust_int","express_shipment","shipping_charge"]]
x =modeling.iloc[:,:-1]
y =modeling.iloc[:,-1:]
X_train, X_test, y_train, y_test = train_test_split(x,y, random_state = 1)
model = LinearRegression()
model.fit(X_train, y_train)
model.predict(X_test)
有人能解释这个问题的正确方法是什么,或者如何解决它吗
这里您使用标签编码器来表示“季节”(1,2,3,4)和线性回归。这意味着您为这个模型分配了一些内在的顺序。您可以尝试对“season_int”进行一种热编码:
https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html
可能的答案:
sklearn.ensemble.RandomForestRegressor
李>似乎您需要一个时间序列模型[是吗?]https://www.statsmodels.org/stable/examples/index.html#time-series-analysis
相关问题 更多 >
编程相关推荐