'predict function producing too high y values

hi can anyone tell me why my linear regression line is being displayed like https://imgur.com/gallery/u3L2avz. i reverted back to a previous version of my python script that was working before however I mustve edited something for it to be displayed like this.

the y values being predicted are: https://pastebin.com/HkR2JzvU

the actual y values are: https://pastebin.com/gTW90urJ

This is my code:

     data = pd.read_csv('food.csv')

     x = data['Date'].values
     x = pd.to_datetime(x, errors="coerce")
      x = x.values.astype("float64").reshape(-1,1)

      y = data['TOTAL'].values.reshape(-1,1)

     reg = LinearRegression()
      reg.fit(x, y)

       print(f"The slope is {reg.coef_[0][0]} and the intercept is {reg.intercept_[0]}")

       predictions = reg.predict(x.reshape(-1, 1))

       x= data['Date'].astype('str')
       plt.scatter(x, y,c='black')
       plt.plot(x, predictions, c='blue', linewidth=2)
        plt.show()


Sources

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

Source: Stack Overflow

Solution Source