1
$\begingroup$

Multiple: y=b0+b1X1+b2X2+b3X3....bnXn

Polynomial: y=b0+b1X+b2(X)^2+....bn(X)^n

Step1: Importing package

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

Step2; Read data using pandas

dataset = pd.read_csv('ordor.csv',delimiter='\t') X=dataset.iloc[:,1:4].values y=dataset.iloc[:,0].values

Step 3: Preprocessing of data: Not Required as there is no categorical data in this dataset

Step 4: Splitting of data into train and test set: Not required as total populationsize is very small (15,4)

step 5: Multiple Linear Regression Classifier.

from sklearn.linear_model import LinearRegression l=LinearRegression() l.fit(X,y) y_pred=l.predict(X)

Step 6: Polynomial Linear Regression Classifier

from sklearn.preprocessing import PolynomialFeatures P=PolynomialFeatures(degree=2) X_poly=P.fit_transform(X) Pl=LinearRegression() Pl.fit(X_poly,y) py_pred=Pl.predict(X_poly)

Visualize the Multiple Regression and Polynomial Regression

plt.scatter(X,y,color='green') plt.plot(X,y_pred,color='blue') plt.title('Multple LR') plt.xlabel('Temp,Ratio,Height') plt.ylabel('Odor') plt.show()

plt.scatter(X,y, color='red') plt.plot(X,py_pred,color='blue') plt.title('Polynomial LR') plt.xlabel('Temp,Ratio,Height') plt.ylabel('Odor') plt.show()

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.