Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This program predicts stock prices with machine learning
- #Install dependencies
- import quandl
- import numpy as np
- from sklearn.linear_model import LinearRegression
- from sklearn.svm import SVR
- from sklearn.model_selection import train_test_split
- #Get the data
- df = quandl.get("WIKI/FB") #df = dataframe
- #Take a look at the data
- print(df.head())
- #Get the adjusted close price
- df = df[["Adj. Close"]]
- #Take a look at the new data
- print(df.head())
- #Variable for the number of days predicting out in the future
- forecast_out = 1
- #Create another column (the target variable) shifted "n" units up
- df['Prediction'] = df[['Adj. Close']].shift(-forecast_out)
- print(df.tail())
- #Create the independent data set (x)
- #Convert the dataframe to numpy array
- X = np.array(df.drop(["Prediction"]),1)
- X = X [:-forecast_out]
- print(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement