Now-a-days, with the technological advancement, Techniques like Machine Learning, etc are being used on a large scale in many organisations. These models usually work with a set of predefined data-points available in the form of datasets. These datasets contain the past/previous information on a specific domain. Organising these datapoints before it is fed to the model is very important. This is where we use Data Analysis. If the data fed to the machine learning model is not well organised, it gives out false or undesired output. This can cause major losses to the organisation. Hence making use of proper data analysis is very important.
The data that we are going to use in this example is about cars. Specifically containing various information datapoints about the used cars, like their price, color, etc. Here we need to understand that simply collecting data isn’t enough. Raw data isn’t useful. Here data analysis plays a vital role in unlocking the information that we require and to gain new insights into this raw data.
Consider this scenario, our friend, Otis, wants to sell his car. But he doesn’t know how much should he sell his car for! He wants to maximize the profit but he also wants it to be sold for a reasonable price for someone who would want to own it. So here, us, being a data scientist, we can help our friend Otis.
Let’s think like data scientists and clearly define some of his problems: For example, is there data on the prices of other cars and their characteristics? What features of cars affect their prices? Colour? Brand? Does horsepower also affect the selling price, or perhaps, something else?
As a data analyst or data scientist, these are some of the questions we can start thinking about. To answer these questions, we’re going to need some data. But this data is in raw form. Hence we need to analyze it first. The data is available in the form of
.csv/.data format with us
To download the file used in this example click here. The file provided is in the .data format. Follow the below process for converting a .data file to .csv file.
Process to convert .data file to .csv:
- open MS Excel
- Go to DATA
- Select From text
- Check box tick on comas(only)
- Save as .csv to your desired location on your pc!
- pandas: Pandas is an opensource library that allows you to perform data manipulation in Python. Pandas provide an easy way to create, manipulate and wrangle the data.
- numpy: Numpy is the fundamental package for scientific computing with Python.
numpycan be used as an efficient multi-dimensional container of generic data.
- matplotlib: Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of formats.
- seaborn: Seaborn is a Python data-visualization library that is based on matplotlib. Seaborn provides a high-level interface for drawing attractive and informative statistical graphics.
- scipy: Scipy is a Python-based ecosystem of open-source software for mathematics, science, and engineering.
Steps for installing these packages:
- If you are using anaconda- jupyter/ syder or any other third party softwares to write your python code, make sure to set the path to the “scripts folder” of that software in command prompt of your pc.
- Then type – pip install package-name
pip install numpy
- Then after the installation is done. (Make sure you are connected to the internet!!) Open your IDE, then import those packages. To import, type – import package name
Steps that are used in the following code (Short description):
- Import the packages
- Set the path to the data file(.csv file)
- Find if there are any null data or NaN data in our file. If any, remove them
- Perform various data cleaning and data visualisation operations on your data. These steps are illustrated beside each line of code in the form of comments for better understanding, as it would be better to see the code side by side than explaining it entirely here, would be meaningless.
- Obtain the result!
Lets start analyzing the data.
Step 1: Import the modules needed.
Step 2: Let’s check the first five entries of dataset.
Step 3: Defining headers for our dataset.
Step 4: Finding the missing value if any.
Step 4: Converting mpg to L/100km and checking the data type of each column.
Step 5: Here, price is of object type(string), it should be int or float, so we need to change it
Step 6: Normalizing values by using simple feature scaling method examples(do for the rest) and binning- grouping values
Step 7: Doing descriptive analysis of data categorical to numerical values.
Step 8: Plotting the data according to the price based on engine size.
Step 9: Grouping the data according to wheel, body-style and price.
Step 10: Using the pivot method and plotting the heatmap according to the data obtained by pivot method
Step 11: Obtaining the final result and showing it in the form of a graph. As the slope is increasing in a positive direction, it is a positive linear relationship.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course