Skip to content

ghulam-ahmad-1/Car-Prize-Prediction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Car Price Prediction with Linear Regression

Introduction

This code is a simple example of using Linear Regression to predict car prices based on various features. It takes advantage of Python's powerful libraries like pandas, matplotlib, and scikit-learn. In this README, we will explain the code step by step and provide a clear understanding of what it does.

Setup

Before running the code, ensure that you have the required libraries installed. You can install them using pip:

pip install pandas scikit-learn matplotlib

Data

The code reads car data from a CSV file named "car_data.csv" using the pandas library. It then drops the "Owner" column, as it is not used for prediction. The target variable (dependent variable) is the "Selling_Price," and the features (independent variables) are all other columns in the dataset.

Data Preprocessing

The code performs some data preprocessing steps:

  1. Encoding Categorical Variables:

    The code uses LabelEncoder from scikit-learn to convert categorical variables like "Car_Name," "Transmission," "Selling_type," and "Fuel_Type" into numerical values. This is necessary as machine learning models require numerical input.

  2. Splitting Data:

    The dataset is split into training and testing sets using train_test_split from scikit-learn. It allocates 70% of the data for training and 30% for testing, ensuring that the data is randomly shuffled for better model generalization.

Model Building

The code uses a simple linear regression model to predict car prices. The steps for building the model are as follows:

  1. Import the LinearRegression class from scikit-learn.
  2. Create a LinearRegression model (regressor).
  3. Fit the model to the training data using the fit() method.

Making Predictions

The code uses the trained model to make predictions on the test data. It uses the predict() method on the model and stores the predictions in the "Y_predict" variable.

Model Evaluation

The code calculates the accuracy of the model using the score() method. This method calculates the coefficient of determination (R-squared) for the model's predictions. The R-squared value measures how well the model fits the data, with higher values indicating a better fit.

Conclusion

This code showcases a basic example of using linear regression to predict car prices. It provides a foundation for more complex machine learning projects and can be extended to include additional features or explore different regression techniques.

Releases

No releases published

Packages

No packages published