Posted by: Sourav | July 10, 2017

Linear Regression example in Python,Python teacher Sourav,Kolkata 09748184075


import pandas as pd
import quandl
import math

data=quandl.get(‘WIKI/GOOGL’)
data=data[[‘Adj. Open’,’Adj. High’,’Adj. Low’,’Adj. Close’,’Adj. Volume’]]
data[‘HL_PCT’]=(data[‘Adj. High’]-data[‘Adj. Close’])/data[‘Adj. Close’]*100.0
data[‘PCT_CHANGE’]=(data[‘Adj. Close’]-data[‘Adj. Open’])/data[‘Adj. Open’]*100.0
data=data[[‘Adj. Close’,’HL_PCT’,’PCT_CHANGE’,’Adj. Volume’]]

 

#print len(data)
forecast_col=’Adj. Close’
data.fillna(-99999,inplace=True)
forecast_out=int(math.ceil(0.0001*len(data)))
data[‘label’]=data[forecast_col].shift(-forecast_out)
print data.head(10)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: