Skip to main content

Polynomial Regression - helpcodes.me

Part 3:  Polynomial Regression : ( Python )

 

Today we will learn more about the Polynomial Regression and which regression is better Linear or Polynomial . The Polynomial vs Linear Regression ? , Polynomial key factor and uses. 
Importing data and Liberaries

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv('position_salaries.csv')
X = dataset.iloc[:, 1:2].values
y = dataset.iloc[:, 2].values



Now we will Splitting the data in train and test data sets 

# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split 
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2
 random_state=0)

Now we will do Linear regression using the Sklearn liberaries inwhich we used LinearReression Class and ' lreg ' Objects

# Fitting Linear Regression to the dataset
from sklearn.linear_model import LinearRegression
lreg = LinearRegression()
lreg.fit(X, y)


After Fitting data in Linear model now we will go Toward Displaying thegraph of Linear Regression and try to figure out in visulisation method 

def vlinear():
    plt.scatter(X, y, color='red')
    plt.plot(X, lreg.predict(X), color='blue')
    plt.title('Truth or Bluff (Linear Regression)')
    plt.xlabel('Position level')
    plt.ylabel('Salary')
    plt.show()
    return
vlinear()

After Completeing the Linear Model now we move forward to ward the Polynomial Model 

The equation of Polynomial Regression is 

            Y = β + β  . X1 + β . X1^2 + β . X2^3  + β . X3^4

 we need the Square term of each Coolum to get the Best prediction and good result .

Now We fill Fit The Data in PolyNomial Regression model :

# Fitting Polynomial Regression to the dataset
from sklearn.preprocessing import PolynomialFeatures
poly_reg = PolynomialFeatures(degree=4)
X_poly = poly_reg.fit_transform(X)
pol_reg = LinearRegression()
pol_reg.fit(X_poly, y)

Now We Fit  The data In Regression model and now we will Visulize the data Using the sklearn libararies and we will compare the linear and Polynomial regression and the output of both are give below in screen shots.

def vpolymonial():
    plt.scatter(X, y, color='red')
    plt.plot(X, pol_reg.predict(poly_reg.fit_transform(X)), color='blue')
    plt.title('Truth or Bluff (Linear Regression)')
    plt.xlabel('Position level')
    plt.ylabel('Salary')
    plt.show()
    return
vpolymonial()




Comparison :
The Polynomial is accurate than the linear and giving best prediction .The polynomial is very closed to exact result and data .


Comments

Popular posts from this blog

what gaming development require ,how the game developed ? -machinelearningtechnilesh

  What is gaming development & requirement? how the game developed? Hellos guys today we are exploring the video gaming industry and how the game is developed by the gaming engineers. The video gaming industry is growing exponentially on a large scale. A large no of games is launched by the many video gaming companies games like GTA 5 ( All series 1,2,3,4,5) by Rockstar studio & Cricket (2007,2010) by EA sports.The game development is also a big future for engineers. Today we are exploring the path to develop the game and which programming language is required and which skill do have to become a gaming developer.  Table Of Contents C# (C Sharp ) The best language for game development is c#. This language is similar to java and c,c++ programming. The Language is best because it used in AR & VR and ios development also. The best part of this programming language is the OOP (object-oriented programming) .this language works on .NET Frameworks. To build a game or AR ...

Sentiment Analysis using NLP Libraries -machinelearningtechnilesh

Doing Sentiment Analysis using NLP Libraries Conclusion from the Frist Approach : Sentiment Analysis using NLP Libraries (Unsupervised learning ) : result and analysis:  1) AFINN lexicon Model Performance metrics: ------------------------------ Accuracy: 0.71 Precision: 0.73 Recall: 0.71 F1 Score: 0.71 The Accuracy is 71% and F1 score tell about the performance of the that is 72%.that getting success is 72%. 2) SentiWordnet Model Performance metrics: ------------------------------ Accuracy: 0.69 Precision: 0.69 Recall: 0.69 F1 Score: 0.68 The Accuracy is 71% and F1 score tell about the performance of the that is 72%.that getting success is 72%. 3) VADER Model Performance metrics: ------------------------------ Accuracy: 0.71 Precision: 0.72 Recall: 0.71 F1 Score: 0.71 The Accuracy is 71% and F1 score tell about the performance of the that is 72%.that getting success is 72%. From comparing all three unsupervised model the AFFIN is best model because the precise value is greater than...

Computer Networks All Basic in one Blog :machinelearningtechnilesh

 . A computer network is formed by two or more devices connected together, these devices might be connected to share data to do some computations together or to share the resources. For example, a simple network where two computers are connected and one printer is connected and these both computers want to give command to the printer. So Resource Sharing is happening Do you do computer networks, computer networks are in fact everywhere they are in our office, they are in our home. In home, we might have multiple devices like laptops, Alexa, or other devices which are connected in a network. in office, you often see networks, your computers connected through a switch or any other device like router, and they form a network. So there are many, many networks that exist. In this course, we are going to focus mainly on internet, the largest network, almost half of the world's population is connected to the internet. In fact, most of our home devices, our office devices, they are connect...