# Python Simple Linear Regression Code

The code for our youtube tutorial Predict Stock Market Using Simple Linear Regression and Python

Python Code for our youtube tutorial is given below

Don't forget to Subscribe to Our Channel and Let us know your thoughts in the comments section of our youtube video

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33``` ``` import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.linear_model import LinearRegression from sklearn import metrics import matplotlib.pyplot as plt from matplotlib import style style.use('ggplot') df = pd.read_csv('datafile.csv') #replace datafile.csv with your csv file print(df.head(25)) x = df[['High Price','Open Price','Low Price','Total Traded Quantity']].values y = df['Close Price'].values x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=0) regressor = LinearRegression() regressor.fit(x_train,y_train) print(regressor.coef_) y_pred = regressor.predict(x_test) result = pd.DataFrame({'Actual':y_test.flatten(),'Predicted':y_pred.flatten()}) result.head(25) print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_pred)) print('Mean Squared Error:', metrics.mean_squared_error(y_test, y_pred)) print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, y_pred))) ```

If you have any doubts or run into any problem feel free to ask them at our youtube video comments here

Featured Image by Mudassar Iqbal from Pixabay

by Kannan

write the code which predict odd or even out come will come with the help of linear regrassion

by help me

## Netlify vs Github Pages Speedtest

Github pages and Netlify are among the most popular choices for hosting static sites. Here we compare them on page load times.

RahulVk April 2 2020 · 10 min read

## Mi Home Security Camera 360 review

by RahulVk
April 10 · 10 min read

## Why you should use a static site generator ?

by RahulVk
March 27 2020 · 15 min read

## How To Install And Configure WP Super Cache Plugin In WordPress In 2019 ??

by RahulVk
March 25 2020 · 5 min read