input: Write a python function to train a linear regression model on given historical stock data and output predictions.
  assert len(train_and_predict(data).predict(X_test)) == len(y_test)
  assert train_and_predict(data).coef_.size == X_train.shape[1]
  assert train_and_predict(data).intercept_ is not None
output: def train_and_predict(data):
      from sklearn.model_selection import train_test_split
      from sklearn.linear_model import LinearRegression
      import numpy as np
      
      X = data.drop(columns='target').values
      y = data['target'].values
  
      X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
  
      model = LinearRegression()
      model.fit(X_train, y_train)
      
      return model