Python for Machine Learning - Polynomial Linear Regression using Scikit Learn - P9
Polynomial Linear Regression using Scikit Learn
In statistics, polynomial regression is a form of regression analysis in which the relationship between the independent variable x and the dependent variable y is modelled as an nth degree polynomial in x. Polynomial regression fits a nonlinear relationship between the value of x and the corresponding conditional mean of y, denoted E(y |x). Although polynomial regression fits a nonlinear model to the data, as a statistical estimation problem it is linear, in the sense that the regression function E(y | x) is linear in the unknown parameters that are estimated from the data. For this reason, polynomial regression is considered to be a special case of multiple linear regression.
y = 9450x + 25792
y = 16.393x2 + 9259.3x + 26215
y = -122.92x3 + 2099.4x2 - 718.71x + 38863
y = 4.9243x4 - 236.59x3 + 2979.9x2 - 3314.2x + 41165
y = 15.006x5 - 430.13x4 + 4409.7x3 - 19368x2 + 43652x + 8315
Code Starts Here
===============
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('SalaryData_Train.csv')
features = df.iloc[:,0:1].values
labels = df.iloc[:,1:2].values
plt.scatter(features,labels)
plt.xlabel('Years of Experience')
plt.ylabel('Salary')
plt.title('Salary V/s Years of Experience')
plt.show()
Step 6 - Sampling
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(features,
labels,
test_size=0.33,
random_state=0)
Create the REgression Model
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
Create The Polynomial Features
from sklearn.preprocessing import PolynomialFeatures
poly_reg = PolynomialFeatures(degree=3)
x_poly = poly_reg.fit_transform(features)
regressor.fit(x_poly,labels)
Test the model
y_pred = regressor.predict(poly_reg.fit_transform(X_test))
Calculate the Accuracy
print('Polynomial Linear Regression Accuracy:',regressor.score(poly_reg.fit_transform(X_test),y_test))
for i in range(1,6):
poly_reg = PolynomialFeatures(degree=i)
x_poly = poly_reg.fit_transform(features)
regressor.fit(x_poly,labels)
print('Degree of Equation :', i)
print('Coefficient :', regressor.coef_)
print('Intercept :', regressor.intercept_)
print('Accuracy Score:', regressor.score(poly_reg.fit_transform(X_test),y_test))
All Playlist of this youtube channel
====================================
1. Data Preprocessing in Machine Learning
• Data Preprocessing in Machine Learning| Li...
2. Confusion Matrix in Machine Learning, ML, AI
• Confusion Matrix in Machine Learning, ML, AI
3. Anaconda, Python Installation, Spyder, Jupyter Notebook, PyCharm, Graphviz
• Anaconda | Python Installation | Spyder | ...
4. Cross Validation, Sampling, train test split in Machine Learning
• Cross Validation | Sampling | train test s...
5. Drop and Delete Operations in Python Pandas
• Drop and Delete Operations in Python Pandas
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 Learning
9. Handling Missing Values in Machine Learning
• Handling Missing Values in Machine Learning
10. Dummy Encoding Encoding in Machine Learning
• Label Encoding, One hot Encoding, Dummy En...
11. Data Visualisation with Python, Seaborn, Matplotlib
• Data Visualisation with Python, Matplotlib...
12. Feature Scaling in Machine Learning
• Feature Scaling in Machine Learning
13. Python 3 basics for Beginner
• Python | Python 3 Basics | Python for Begi...
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 Machine Lea...
18 Interiew Questions on Machine Learning and Data Science
• Interview Question for Machine Learning, D...
19. Jupyter Notebook Operations
• Jupyter and Spyder Notebook Operations in ...
Nesta página do site você pode assistir ao vídeo on-line Python for Machine Learning - Polynomial Linear Regression using Scikit Learn - P9 duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário technologyCult 25 Março 2018, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 5,756 vezes e gostou 49 espectadores. Boa visualização!