Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #This program predicts stock prices with machine learning
  2.  
  3. #Install dependencies
  4.  
  5. import quandl
  6. import numpy as np
  7. from sklearn.linear_model import LinearRegression
  8. from sklearn.svm import SVR
  9. from sklearn.model_selection import train_test_split
  10.  
  11. #Get the data
  12.  
  13. df = quandl.get("WIKI/FB") #df = dataframe
  14.  
  15. #Take a look at the data
  16.  
  17. print(df.head())
  18.  
  19. #Get the adjusted close price
  20.  
  21. df = df[["Adj. Close"]]
  22.  
  23. #Take a look at the new data
  24.  
  25. print(df.head())
  26.  
  27. #Variable for the number of days predicting out in the future
  28.  
  29. forecast_out = 1
  30.  
  31. #Create another column (the target variable) shifted "n" units up
  32.  
  33. df['Prediction'] = df[['Adj. Close']].shift(-forecast_out)
  34.  
  35. print(df.tail())
  36.  
  37. #Create the independent data set (x)
  38. #Convert the dataframe to numpy array
  39.  
  40. X = np.array(df.drop(["Prediction"]),1)
  41.  
  42. X = X [:-forecast_out]
  43.  
  44. print(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement