Странная вещь происходит сегодня.Я бегу RandomForestRegressor
по 8 категориям.Сначала я попытался зациклить график функции y_test
и мой прогноз, но затем я заметил, что эти графики не соответствуют моим результатам в другом месте скрипта, поэтому я попытался запустить превращение функции в простой скрипт.Цикл функции плюс выглядит следующим образом:
def plotModelResults(model, X_train=X_train, X_test=X_test, plot_intervals=False, plot_anomalies=False):
model.fit(X_train.values,y_train.values.ravel())
prediction = model.predict(X_test.values)
axs[i].plot(prediction, "g", label="prediction", linewidth=2.0)
axs[i].plot(y_test.values.ravel(), label="actual", linewidth=2.0)
axs[i].legend(loc="best")
axs[i].set_title('{}'.format(team))
axs[i].grid(True)
Ничего особенного.И это выглядит так:
nplots=df['Equipos'].nunique()
f, axs = plt.subplots(figsize=(25,5),nrows=1, ncols=nplots, sharey=True )
dicc=dict()
for i,team in enumerate(df['Equipos'].unique()):
aux=df.loc[df['Equipos']==team]
X=aux.drop(columns=['Cantidad_Vendida','Equipos']).copy()
y=aux[['Cantidad_Vendida']].copy()
X_train, X_test, y_train, y_test = timeseries_train_test_split(X, y, test_size=0.1)
plt.tight_layout()
plotModelResults(RandomForestRegressor(n_estimators=100, random_state=42))
Первый график из этого скрипта выглядит так:

И затем язапустите это:
nplots=len(df['Equipos'].unique())
f, axs = plt.subplots(figsize=(25,5),nrows=1, ncols=nplots, sharey=True )
for i,team in enumerate(df['Equipos'].unique()):
aux=df.loc[df['Equipos']==team]
X=aux.drop(columns=['Fecha_Venta','Cantidad_Vendida','Equipos']).copy()
y=aux[['Cantidad_Vendida']].copy()
X_train, X_test, y_train, y_test = timeseries_train_test_split(X, y, test_size=0.1)
rf=RandomForestRegressor(n_estimators=100, random_state=42)
#Fiteamos modelo
rf.fit(X_train.values,y_train.values.ravel())
prediction = rf.predict(X_test.values)
axs[i].plot(prediction, "g", label="prediction", linewidth=2.0)
#Ploteamos valores de test
axs[i].plot(y_test.values.ravel(), label="actual", linewidth=2.0)
axs[i].legend(loc="best")
axs[i].set_title('{}'.format(team))
axs[i].grid(True)
plt.tight_layout()
Из которого его первый график выглядит так:

Насколько я вижу, обаСценарии эквивалентны, поэтому я понятия не имею, почему эти графики отличаются.Есть идеи?