text_plain_output_1.png image_output_1.png
from sklearn.linear_model import LinearRegression

import matplotlib.pyplot as plt

import numpy as np

import os

import pandas as pd

data = pd.read_csv('/kaggle/input/heightvsweight-for-linear-polynomial-regression/HeightVsWeight.csv')

x = data.iloc[:, :-1].values
y = data.iloc[:, -1].values

from sklearn.linear_model import LinearRegression
lin_reg = LinearRegression()
lin_reg.fit(x, y)

from sklearn.preprocessing import PolynomialFeatures
poly_reg = PolynomialFeatures(degree=3)
x_poly = poly_reg.fit_transform(x)
lin_reg2 = LinearRegression()
lin_reg2.fit(x_poly, y)

x_grid = np.arange(min(x), max(x), 0.1)
x_grid = x_grid.reshape((len(x_grid), 1))
plt.scatter(x, y, color='red')
plt.plot(x, lin_reg2.predict(x_poly), color='blue')
plt.xlabel('Age')
plt.ylabel('Height')
plt.title('Polynomial Linear Regression ')