<jupyter_start><jupyter_text>Polynomial Linear regression    y = b0 + b1*x1 + b2*x1^2 + .... + bn*x1^n    Note: Linear beacuse we are takling of y in respect to bi(coefficients)<jupyter_code># Importing the libraries
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
dataset.head(2)
plt.scatter(X, y, color="blue")
plt.xlabel("Level")
plt.ylabel("Salary")
plt.title("Non linear dependencies between level and salary")
# Splitting the dataset into the Training set and Test set

"""
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
"""

# Feature Scaling
"""from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
X_train = sc_X.fit_transform(X_train)
X_test = sc_X.transform(X_test)
sc_y = StandardScaler()
y_train = sc_y.fit_transform(y_train)"""<jupyter_output><empty_output><jupyter_text>Fitting linear regression to the dataset<jupyter_code>from sklearn.linear_model import LinearRegression

linear_regressor = LinearRegression()
linear_regressor.fit(X, y)<jupyter_output><empty_output><jupyter_text>Fitting polynomial regression to the dataset<jupyter_code>from sklearn.preprocessing import PolynomialFeatures

poly_regressor = PolynomialFeatures(degree = 5)
x_poly = poly_regressor.fit_transform(X)
x_poly
# x_poly = poly_regressor.fit_transform(X)
linear_regressor2 = LinearRegression()
linear_regressor2.fit(x_poly, y)<jupyter_output><empty_output><jupyter_text>Visualizing the linear regression results<jupyter_code>plt.scatter(X, y, color = "red")
plt.plot(X, linear_regressor.predict(X), color = "blue")

plt.title("Truth or bluff Linear Regression")
plt.xlabel("Position Level")
plt.xlabel("Salary")
plt.show()<jupyter_output><empty_output><jupyter_text>Visualizing the Polynomial regression results<jupyter_code>plt.scatter(X, y, color = "red")
plt.plot(X, linear_regressor2.predict(poly_regressor.fit_transform(X)), color = "blue")

plt.title("Truth or bluff Polynomial Regression")
plt.xlabel("Position Level")
plt.xlabel("Salary")
plt.show()
x_grid = np.arange(min(X), max(X), 0.25)
x_grid = x_grid.reshape((len(x_grid), 1))

plt.scatter(X, y, color = "red")
plt.plot(x_grid, linear_regressor2.predict(poly_regressor.fit_transform(x_grid)), color = "blue")

plt.title("Truth or bluff Polynomial Regression")
plt.xlabel("Position Level")
plt.xlabel("Salary")
plt.show()<jupyter_output><empty_output><jupyter_text>Prediction of new result - Linear<jupyter_code>data = np.array([2.5, 3.5, 5.2, 7,8]).reshape(-1, 1)
linear_regressor.predict(data)<jupyter_output><empty_output><jupyter_text>Prediction of new result - Polynomial<jupyter_code>data = np.array([2.5, 3.5, 5.2, 7,8]).reshape(-1, 1)
linear_regressor2.predict(poly_regressor.fit_transform(data))
dataset<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13004032258064516, 'fraction_numerical': 0.01478494623655914, 'mean_word_length': 7.65406976744186, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '61991', 'license': 'MIT', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1081, 'n_words': 216, 'path': 'regression/polynomial/polynomial_regression.ipynb', 'repo_name': 'jai-singhal/data_science', 'size': '2976'}