'Could anyone tell me why in X, 'time' has a bracket, but in y 'sales' does not need it? They are just the name for different columns. Why different?

from sklearn.linear_model import LinearRegression

df = average_sales.to_frame()

time = np.arange(len(df.index))  # time dummy

df['time'] = time

X = df.loc[:, ['time']]  # features

y = df.loc[:, 'sales']  # target

model = LinearRegression()

model.fit(X, y)

y_pred = pd.Series(model.predict(X), index=X.index)

Could anyone tell me why in X, 'time' has a bracket, but in y 'sales' does not need it? They are just the name for different columns. Why different?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source