# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
"""
Linear regression uses the relationship between the data-points to draw a straight line through all them.

This line can be used to predict future values.

Example: 

The x-axis represents age, and the y-axis represents speed. We have registered the age and speed of 13 cars as they were passing a tollbooth.

Let us see if the data we collected could be used in a linear regression:
"""
import matplotlib.pyplot as plt
from scipy import stats

#x=no. of years of cars
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]

#y=speed of the car
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]


plt.scatter(x, y)

plt.show()


slope, intercept, r, p, std_err = stats.linregress(x, y)

def myfunc(x):
  return slope * x + intercept

mymodel = list(map(myfunc, x))

plt.scatter(x, y)
plt.plot(x, mymodel)
plt.show()

speed = myfunc(13)

print("Speed of car after 13 years:")
print(speed)