<jupyter_start><jupyter_text>https://www.youtube.com/watch?v=EYnC4ACIt2g<jupyter_code>pip install quandl
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
df = quandl.get("WIKI/FB")
print(df.head())
# Check the current directory and print it out
import os
print( os.getcwd() )
# Mount the Google drive to talk with the root of colab
from google.colab import drive
drive.mount('/content/gdrive')
# Check the current directory and print it out
print( os.getcwd() )
# Save dataframe to the root
df.to_csv('data.csv')
# Transfer data from root to Google Drive
!cp data.csv "/content/gdrive/My Drive"
# an example of writing a string
with open('/content/gdrive/My Drive/file.txt', 'w') as f:
  f.write("content")
# end this example
# Call the dataframe from the google drive
df2 = pd.read_csv("/content/gdrive/My Drive/data.csv")
df = df2
df=df.set_index('Date')
df
df = df[['Adj. Close']]
print(df.head())
# A variable for predicting 'n' days out into the future
forecast_out = 30
# Create another column (the target or dependent variable) shifted 'n' units up
df['Prediction'] = df[['Adj. Close']].shift(-forecast_out)
# Print(df.head())
print(df.head())
print(df.tail())
### Create the independent data set (X) ###
# Convert the datagrame to a numpy array
X = np.array(df.drop(['Prediction'],1))
# Remove the last 'n' row
X = X[:-forecast_out]
print(X)

### Create the dependent data set (y) ###
# Convert the datagrame to a numpy array (All of the values including the NaN's)
y = np.array(df['Prediction'])
# Get all of the y values except the last 'n'rows
y = y[:-forecast_out]
print(y)
# Split the data into 80% training and 20% testing
x_train,x_test,y_train,y_test = train_test_split(X,y, test_size = 0.2)
# Create and train the Support Vector Machine (Regressor)
svr_rbf = SVR(kernel='rbf',C=1e3, gamma=0.1)
svr_rbf.fit(x_train, y_train)
# Testing Model: Score returns the coefficient of determination R^2 of the prediction
# The best possible score is 1.0
svm_confidence = svr_rbf.score(x_test,y_test)
print("svm confidence: ", svm_confidence)

# Create and train the Linear Regression Model
lr = LinearRegression()
# Train the Model
lr.fit(x_train, y_train)
# Testing Model: Score returns the coefficient of determination R^2 of the prediction
# The best possible score is 1.0
lr_confidence = lr.score(x_test,y_test)
print("lr confidence: ", lr_confidence)
# Set x_forecast equal to the last 30 rows of the original data set from Adj. Close column
x_forecast = np.array(df.drop(['Prediction'],1))[-forecast_out:]
print(x_forecast)
# Print linear regression model predictions for the next 'n' days
lr_prediction = lr.predict(x_forecast)
print(lr_prediction)

# Print support vector regression model predictions for the next 'n' days
svm_prediction = svr_rbf.predict(x_forecast)
print(svm_prediction)<jupyter_output>[177.08725448 183.52431676 183.968949   181.34157664 179.97736407
 181.89736695 182.98873701 187.33400668 188.99127232 185.48474075
 182.31168336 179.90662712 180.59378605 184.41358125 183.78705399
 187.75842837 186.37400524 189.29443067 188.81948259 185.90916244
 188.24348173 187.91000754 189.15295677 176.49104306 172.03461532
 173.28766983 168.74029459 163.18239153 163.85944517 155.90659115]
[176.9772862  181.21669313 179.89413781 174.5914663  171.63664029
 177.8475503  181.89126625 187.20647005 179.04419262 181.17386159
 180.11086532 171.6882011  171.89274521 178.83637012 180.45731349
 185.31177969 186.33961294 178.72933492 179.52391138 183.72822511
 182.38192958 184.43024422 178.79049423 178.3644724  171.31480923
 171.95800365 171.84232589 167.34492454 167.89151319 161.63256574]