<jupyter_start><jupyter_text>Importing Libraries and Dataset<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings("ignore", category=FutureWarning)

%matplotlib inline
automob= pd.read_csv(r"C:\Users\shruti\Desktop\Decodr Session Recording\Project\Decodr Project\Predict Mileage based on Technical Specifications of Automobile\auto-mpg.csv")
automob.head()
automob.tail()<jupyter_output><empty_output><jupyter_text>Data Processing<jupyter_code># Removing unnecessary columns

automob.drop(["car name"], axis=1, inplace= True)
automob.head()
automob.describe()
# Checking for Null Values

automob.isnull().sum()
# Checking for False Values

automob["horsepower"].unique()
automob= automob[automob.horsepower!= "?"]
"?" in automob
automob.shape<jupyter_output><empty_output><jupyter_text>Correlation Matrix<jupyter_code>automob.corr()["mpg"].sort_values()
# Plotting Heatmap of Correlation

plt.figure(figsize=(10,10))
sns.heatmap(automob.corr(), annot=True, linewidths= 0.5, center= 0, cmap= "rainbow")
plt.show()<jupyter_output><empty_output><jupyter_text>Univariate Analysis<jupyter_code>sns.countplot(automob.cylinders, data= automob, palette="rainbow")
plt.show()
sns.countplot(automob["model year"], palette= "rainbow")
plt.show()
sns.countplot(automob["origin"], palette= "rainbow")
plt.show()<jupyter_output><empty_output><jupyter_text>Multivariate Analysis<jupyter_code>sns.boxplot(x= "cylinders", y= "mpg", data= automob, palette= "rainbow")
plt.show()
sns.boxplot(x= "model year", y= "mpg", data= automob, palette= "rainbow")
plt.show()
# Modelling Dataset

x=automob.iloc[:,1:].values
y=automob.iloc[:,0].values<jupyter_output><empty_output><jupyter_text>Train and test data split<jupyter_code>from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test= train_test_split(x,y,test_size=0.3, random_state=0)<jupyter_output><empty_output><jupyter_text>Building the Model<jupyter_code>from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
regression= LinearRegression()
regression.fit(x_train, y_train)
y_pred= regression.predict(x_test)
print(regression.score(x_test, y_test))<jupyter_output>0.8191428142279117<jupyter_text>Polynomial Regression<jupyter_code>from sklearn.preprocessing import PolynomialFeatures
poly_reg= PolynomialFeatures(degree=2)
x_poly= poly_reg.fit_transform(x)
x_train, x_test, y_train, y_test= train_test_split(x_poly,y,test_size=0.3, random_state=0)

lin_regression= LinearRegression()
lin_regression.fit(x_train, y_train)

print(lin_regression.score(x_test, y_test))<jupyter_output>0.83420859261561<jupyter_text>Conclusion<jupyter_code>Accuracy score improves in Polynomial Regression compared to Linear Regression because it fits data much better.<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12151123213070116, 'fraction_numerical': 0.016678012253233492, 'mean_word_length': 10.347490347490348, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '384925', 'license': 'Unlicense', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1059, 'n_words': 184, 'path': 'Project2- Predicted Mileage based on Technical Specification of Automobile.ipynb', 'repo_name': 'Shruti0630/Shruti_PythonProject2', 'size': '2938'}