Posts

Showing posts with the label Polynomial Regression

Polynomial Regression Python Code - Loan Default Prediction

Image
Import necessary libraries import pandas import numpy import matplotlib.pyplot from sklearn.linear_model import LinearRegression from sklearn.preprocessing import PolynomialFeatures Importing data into project data = pandas.read_csv('loan_default_rate_dataset.csv') print(data) Assign Input Columns to X variable and Output column to Y Variable x = data[['Credit_Score','Annual_Income','Loan_Amount']] y = data['Loan_Default_Probability'] Importing Polynomial Features to do cross connections, squares in x data. So data will expand and model can learn unpredictable patterns poly = PolynomialFeatures(degree=2) training the X variable using the polynomial feature. So it will do cross connections, squares in x data and learn the complex patterns. x_poly = poly.fit_transform(x) Now, since we learned the complex patterns and expanded the x values into x_poly variable, we can do linear regression from the Polynomial X data and Y data. model = LinearRegres...

What is Polynomial Regression? Linear Regression vs Polynomial Regression

Image
 Polynomial Regression is an Advance method of Linear Regression. Linear Regression draws a line between X and Y data values, we can check how well the relationship between X and Y. Polynomial Regression draws a Curved Line which bends when relationship is unpredictable and non Linear. In a non-linear relationship , the connection between X and Y is not consistent.  Sometimes when X increases , Y increases , Other times when X increases , Y decreases , and it can change direction multiple times . Linear Regression → works best when the relationship between X and Y is proportional and predictable . The line just shows how much Y increases when X increases. Polynomial Regression → works best when the relationship is non-linear or unpredictable . The curve bends up and down showing that sometimes X increases Y, sometimes decreases Y, depending on the data pattern.