Python for Machine Learning | Line of Best Fit in Linear Regression | Cost Function - P86
Python for Machine Learning - Session # 86
Topic to be covered - Minimize Error in Linear Regression
Code Starts Here
==============
import numpy as np
import matplotlib.pyplot as plt
X = np.array([0,0.5,1,1.1,1,5,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10])
Y = np.array([2,2.3,2.5,3.2,2.1,3.3,4.5,2.9,6.4,4.8,5,5.5,6.9,6.3,6.2,7.4,7.5,7.8,8.8,10.4,9.6,9.9,])
plt.scatter(X,Y)
plt.show()
m = (Y.dot(X) - Y.mean()*X.sum()) / ( X.dot(X) - X.mean()* X.sum() )
c = ( Y.mean() * X.dot(X) - X.mean() * Y.dot(X)) / ( X.dot(X) - X.mean()* X.sum() )
Y_hat = m*X + c
plt.scatter(X,Y)
plt.plot(X,Y_hat)
plt.show()
'''R2 = 1 - (SSR / SSM)'''
SSR = Y - Y_hat
SSM = Y - Y.mean()
R2 = 1 - (SSR.dot(SSR)) / (SSM.dot(SSM))
print('R Sqaure :', R2)
All Playlist of this youtube channel
============================
1. Data Preprocessing in Machine Learning
• Data Preprocessing in Machine Learnin...
2. Confusion Matrix in Machine Learning, ML, AI
• Confusion Matrix in Machine Learning,...
3. Anaconda, Python Installation, Spyder, Jupyter Notebook, PyCharm, Graphviz
• Anaconda | Python Installation | Spyd...
4. Cross Validation, Sampling, train test split in Machine Learning
• Cross Validation | Sampling | train t...
5. Drop and Delete Operations in Python Pandas
• Drop and Delete Operations in Python ...
6. Matrices and Vectors with python
• Matrices and Vectors with python
7. Detect Outliers in Machine Learning
• Detect Outliers in Machine Learning
8. TimeSeries preprocessing in Machine Learning
• TimeSeries preprocessing in Machine L...
9. Handling Missing Values in Machine Learning
• Handling Missing Values in Machine Le...
10. Dummy Encoding Encoding in Machine Learning
• Label Encoding, One hot Encoding, Dum...
11. Data Visualisation with Python, Seaborn, Matplotlib
• Data Visualisation with Python, Matpl...
12. Feature Scaling in Machine Learning
• Feature Scaling in Machine Learning
13. Python 3 basics for Beginner
• Python | Python 3 Basics | Python for...
14. Statistics with Python
• Statistics with Python
15. Sklearn Scikit Learn Machine Learning
• Sklearn Scikit Learn Machine Learning
16. Python Pandas Dataframe Operations
• Python Pandas Dataframe Operations
17. Linear Regression, Supervised Machine Learning
• Linear Regression | Supervised Machin...
18 Interiew Questions on Machine Learning, Artificial Intelligence, Python Pandas and Python Basics
• Interview Question for Machine Learni...
19. Jupyter Notebook Operations
• Jupyter and Spyder Notebook Operation...