<jupyter_start><jupyter_text>Importing Libraries<jupyter_code>import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Importing the dataset (.csv file)<jupyter_code>data_frame = pd.read_csv('../Dataset/car data.csv')<jupyter_output><empty_output><jupyter_text>Features of the Dataset<jupyter_code>data_frame.head(10)
data_frame.info()
data_frame.shape
data_frame.drop('Owner', inplace=True, axis=1)
data_frame.head()
data_frame['Fuel_Type'].value_counts()
data_frame['Seller_Type'].value_counts()
data_frame['Transmission'].value_counts()<jupyter_output><empty_output><jupyter_text>Data Visualization<jupyter_code>histograms = data_frame.hist(bins = 50, figsize = (15, 10))<jupyter_output><empty_output><jupyter_text>Handling Categorical Variables<jupyter_code>data_frame.replace({'Fuel_Type' : {'Petrol' : 0, 'Diesel' : 1, 'CNG': 2}}, inplace = True)
data_frame.replace({'Seller_Type' : {'Dealer' : 0, 'Individual' : 1}}, inplace = True)
data_frame.replace({'Transmission' : {'Manual' : 0, 'Automatic' : 1}}, inplace = True)
data_frame.head()<jupyter_output><empty_output><jupyter_text>Importing Libraries for Linear Regression<jupyter_code>from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn import metrics
X = data_frame.drop(['Car_Name', 'Selling_Price'], axis = 1) 
Y = data_frame['Selling_Price']<jupyter_output><empty_output><jupyter_text>Splitting data into training and testing set<jupyter_code>X_train, X_valid, Y_train, Y_valid = train_test_split(X, Y, test_size = 0.25, random_state = 99)
Training_Lr_model = LinearRegression()
Training_Lr_model.fit(X_train, Y_train)<jupyter_output><empty_output><jupyter_text>Training the regression model<jupyter_code>model_pred = Training_Lr_model.predict(X_valid)<jupyter_output><empty_output><jupyter_text>Computing the R-Squared Error<jupyter_code>error_score_valid = metrics.r2_score(Y_valid, Training_Lr_model.predict(X_valid))
error_score_train = metrics.r2_score(Y_train, Training_Lr_model.predict(X_train))
print(error_score_train, error_score_valid)<jupyter_output>0.8701437844386817 0.8971336593351005<jupyter_text>Plot of Real Price Vs Predicted Price of Car Sales<jupyter_code>plt.scatter(Y_valid, model_pred)
plt.xlabel("Real Price")
plt.ylabel("Predicted Price")
plt.title("Real Vs Predicted Car Price")
plt.show()
plt.scatter(Y_valid, model_pred, label = 'Valid')
plt.scatter(Y_train, Training_Lr_model .predict(X_train), label = 'Train')
plt.xlabel("Actual Price")
plt.ylabel("Predicted Price")
plt.title("Actual Vs Predicted Car Price")
plt.show()<jupyter_output><empty_output><jupyter_text>Linear Regression Prediction using Ordinary Least Squares Method(OLS)<jupyter_code>import statsmodels.api as sm
model = sm.OLS(Y_valid, model_pred).fit()
model_prediction = model.predict(model_pred) 

model_details = model.summary()
print(model_details)<jupyter_output>OLS Regression Results                                
=======================================================================================
Dep. Variable:          Selling_Price   R-squared (uncentered):                   0.954
Model:                            OLS   Adj. R-squared (uncentered):              0.954
Method:                 Least Squares   F-statistic:                              1569.
Date:                Sat, 17 Jul 2021   Prob (F-statistic):                    4.93e-52
Time:                        23:24:12   Log-Likelihood:                         -138.22
No. Observations:                  76   AIC:                                      278.4
Df Residuals:                      75   BIC:                                      280.8
Df Model:                           1                                                  
Covariance Type:            nonrobust                                                  
================================[...]
{'fraction_non_alphanumeric': 0.13256048387096775, 'fraction_numerical': 0.026461693548387098, 'mean_word_length': 3.6859504132231407, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '307508', 'license': 'CC0-1.0', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1282, 'n_words': 226, 'path': 'src/reg_ml.ipynb', 'repo_name': 'shiva-s30/265460-Python-MiniProject', 'size': '3968'}