Mobile Price Prediction Using Machine Learning
Hello Everyone My Name is Nivitus. Welcome to the Mobile Price Prediction Tutorial. This is another Machine Learning Blog on Medium Site. I hope all of you like this blog. OK let’s get start the prediction of mobile prices in different varieties.
So far so good, today we are going to work on a dataset which consist information about the various kinds mobile data and its price and other aspects such as RAM, ROM etc. When we work on these sorts of data, we need to see which column is important for us and which is not. Our main aim today is to make a model which can give us a good prediction on the price of the mobile on other Features.
We are going to use Random Forest Regression and Support Vector Regression for this dataset and see if it gives us a good accuracy or not. Before we get started I’d like say some about my blog and my project. In this project is full of developed by myself. Start from data collection from one of the E-Commerce website to Model Deployment. OK Let’s move!!
Table of Contents
· Overview
· Motivation
· Understand the Problem Statement
· About the Dataset
· About the Web Scrapping
· About the Algorithms used in
· Data Collections
· Data Preprocessing
· Exploratory Data Analysis(EDA)
· Feature Observation
· Feature Selection
· Model Building
· Model Performances
· Prediction and Final Score
· Output & Conclusion
Overview
In this Blog we are going to do implementing a salable model for predicting the mobile price prediction using some of the regression techniques based of some of features in the dataset which is called mobile Price Prediction. There are some of the processing techniques for creating a model. In this project i used web scrapping techniques for collecting the mobile data from E-Commerce website. We will see about it in upcoming parts …
Motivation
The Motivation behind it I just wanna know about the various kinds of mobile prices during the lock down period. Because now a days most of the E-Commerce website are focusing to sell the mobile for consumers.
Because now a days many of the students including me also having the online class rooms for continue our education systems. So I got the idea about to do some of the useful things do in the lock down period. That’s why I decided to doing in this project. As well as one of my brother asked to me “Bro why shouldn’t we do this mobile price prediction from end to end? Like we are not going to do get the data from Kaggle for this project” .So I decided to make in this way.
Understand the Problem Statement
Mobile prices are an important reflection of the Humans and some ranges are of great interest for both buyers and sellers. Ask a mobile buyer to describe their dream Mobile or Branded Mobile Phones. So in this blog we are going to see about how the prices are segregated based on the some of the features. As well as the target feature prediction based on the same features.
About the Dataset
In this dataset I wasn’t downloading from Kaggle or any other data collecting websites. I just make or create the dataset using one of the web scrapping tools. I’ll tell about next upcoming part. So a little bit of overview we understand about the data and its features.
# lets understand features of this datasetdf.columnsIndex([‘Brand me’, ‘Ratings’, ‘RAM’, ‘ROM’, ‘Mobile_Size’, ‘Primary_Cam’,‘Selfi_Cam’, ‘Battery_Power’, ‘Price’],dtype=’object’)
Data Overview
- 1. Brand me — This is first feature of our dataset. Its Denotes name of the mobile phones and Brands.
- 2. Ratings — This Feature Denotes Number of the ratings gave by the consumers for each mobile.
- 3. RAM — It’s have RAM size of the phone.
- 4. ROM — It’s have ROM (Internal Memory) size of the phone.
- 5. Mobile_Size — It’s represents how many inches of the particular mobile phone have. Here all the values are gave in inches
- 6. Primary_Cam — It’s Denotes Number of the pixels of the primary camera (Back Camera) for each mobile.
- 7. Selfi_Cam — It’s Denotes Number of the pixels of the Selfi camera (Front Camera) for each mobile.
- 8. Battery_Power — It’s Denotes amount of the battery power in each mobiles in mAh.
- 9. Price — It’s a Dependent Feature of the dataset. It’s just denoting prices of the each mobile.
About the Web Scrapping
In this project I wasn’t get the dataset from Kaggle rather than I got an idea about download from mobile websites. So I decided using web scrapping method. So we should understand one thing what is web scrapping? Web scraping, web harvesting, or web data extraction is data scraping used for extracting data from websites.
Web scraping software may access the World Wide Web directly using the Hypertext Transfer Protocol, or through a web browser. Wanna more about web scrapping just click here.
Here I was use this tool for getting data from one of the E-Commerce website. This is a tool for using web scrapping any data from any websites. You can also use python coding for web scrapping. Now I’m just a beginner for web scrapping that’s why I used a tool for getting data. Next upcoming days I develop my web scrapping coding skills. If you wanna this tool for getting your data just click it for Download.
About the Algorithms used in
The major aim of in this project is to predict the house prices based on the features using some of the regression techniques and algorithms.
1. Random Forest Regressor
2. Support Vector Regressor
Machine Learning Packages are used for in this Project
Data Collection
Here if you search the dataset in Kaggle you won’t be get the same dataset from Kaggle. But you’ll be getting another kind of datasets like that. So Data collection part I already mentioned to you using web scrapping method to collecting the data from one of the E-Commerce website in Mobile sections. So here I’d like mentioned the link for you’ll be getting the data. If you wanna get the dataset just click here.
After download the dataset the dataset will be look like.
Note: After you should drop out the first column that’s Unnamed: 0 column.
Data Preprocessing
Data preprocessing is an important step in the data mining process. The phrase “garbage in, garbage out” is particularly applicable to data mining and machine learning projects. Data-gathering methods are often loosely controlled, resulting in out-of-range values, impossible data combinations, missing values, etc.
In this project you might be performing lot of preprocessing steps. Because in this dataset is not downloaded from Kaggle or any other data source website. This data retrieve from E-Commerce website. But after I was get the dataset I was make a dataset for model prediction. So you need not to and data preprocessing steps except handling the missing values.
# Shape of the Datasetprint(“Shape of Training dataset:”, df.shape)Shape of Training dataset: (836, 9)# Checking null values for training datasetdf.isnull().sum()
Handling the missing values
# Fill up the mean values of all the missing value columns into the datasetdf[‘Ratings’] = df[‘Ratings’].fillna(df[‘Ratings’].mean())df[‘RAM’] = df[‘RAM’].fillna(df[‘RAM’].mean())df[‘ROM’] = df[‘ROM’].fillna(df[‘ROM’].mean())df[‘Mobile_Size’] = df[‘Mobile_Size’].fillna(df[‘Mobile_Size’].mean())df[‘Selfi_Cam’] = df[‘Selfi_Cam’].fillna(df[‘Selfi_Cam’].mean())
Note: We need not to have the Brand me feature for prediction because it just a mobile name. So we should drop the first column.
Get Nivitus’s stories in your inbox
Join Medium for free to get updates from this writer.
After handling all the null or missing values will be look like
Data Types Changing
# Data Typesdf.dtypes()
Note: Here some of the data types are floating point values. We need to change the into integer values except Rating feature.
# Changing the Datatypedf[‘RAM’] = df[‘RAM’].astype(‘int64’)df[‘ROM’] = df[‘ROM’].astype(‘int64’)df[‘Selfi_Cam’] = df[‘Selfi_Cam’].astype(‘int64’)
Note: After changing the data types dataset and data types will be look like.
Exploratory Data Analysis
In statistics, exploratory data analysis (EDA) is an approach to analyzing data sets to summarize their main characteristics, often with visual methods. A statistical model can be used or not, but primarily EDA is for seeing what the data can tell us beyond the formal modeling or hypothesis testing task.
# Information about the dataset featuresdf.info()
# Describedf.describe()
Feature Observation
# Finding out the correlation between the featurescorr = df.corr()corr.shape
First Understanding the correlation of features between target and other features
# Plotting the heatmap of correlation between featuresplt.figure(figsize=(14,14))sns.heatmap(corr, cbar=False, square= True, fmt=’.2%’, annot=True, cmap=’Greens’)
# Checking the null values using heatmap# There is any null values are occupyed heresns.heatmap(df.isnull(),yticklabels=False,cbar=False,cmap=’viridis’)
plt.figure(figsize=(15,10))sns.set_style(‘whitegrid’)sns.countplot(x=’Ratings’,data=df)
plt.figure(figsize=(15,10))sns.set_style(‘whitegrid’)sns.countplot(x=’RAM’,data=df)
plt.figure(figsize=(15,10))sns.set_style(‘whitegrid’)sns.countplot(x=’ROM’,data=df)
plt.figure(figsize=(15,10))sns.set_style(‘whitegrid’)sns.countplot(x=’Primary_Cam’,data=df)
plt.figure(figsize=(15,10))sns.set_style(‘whitegrid’)sns.countplot(x=’Selfi_Cam’,data=df)
sns.distplot(df[‘RAM’].dropna(),kde=False,color=’darkred’,bins=10)
sns.distplot(df[‘Battery_Power’].dropna(),kde=False,color=’green’,bins=10)
sns.distplot(df[‘Price’].dropna(),kde=False,color=’darkblue’,bins=15)
sns.distplot(df[‘Battery_Power’].dropna(),kde=False,color=’darkblue’,bins=15)
plt.figure(figsize=(10,10))sns.pairplot(data=df)
Feature Selection
Feature Selection is the process where you automatically or manually select those features which contribute most to your prediction variable or output in which you are interested in. Having irrelevant features in your data can decrease the accuracy of the models and make your model learn based on irrelevant features.
# Lets try to understand which are important feature for this datasetfrom sklearn.feature_selection import SelectKBestfrom sklearn.feature_selection import chi2
Importing Libraries
X = df.iloc[:,1:7] # Independent columnsy = df.iloc[:,[-1]] # Y target column i.e price range
Values Assigning
# Apply SelectKBest class to extract top 10 best featuresbestfeatures = SelectKBest(score_func=chi2, k=4)fit = bestfeatures.fit(X,y)
Fitting Method
dfscores = pd.DataFrame(fit.scores_)dfcolumns = pd.DataFrame(X.columns)# Concat two dataframes for better visualizationfeatureScores = pd.concat([dfcolumns,dfscores],axis=1)featureScores.columns = [‘Specs’,’Score’] #naming the dataframe columnsfeatureScores
print(featureScores.nlargest(4,’Score’)) #print 4 best featuresFeature Importance
from sklearn.ensemble import ExtraTreesClassifierimport matplotlib.pyplot as pltmodel = ExtraTreesClassifier()model.fit(X,y)
print(model.feature_importances_) # use inbuilt class feature_importances of tree based classifiers[0.12253721 0.109504 0.26739755 0.09270551 0.20932722 0.19852852]# Plot graph of feature importances for better visualizationfeat_importances = pd.Series(model.feature_importances_, index=X.columns)feat_importances.nlargest(10).plot(kind=’barh’)plt.show()
Model Fitting
Random Forest Regressor
Support Vector Regressor
Model Performance
Random Forest Regressor
Support Vector Regressor
Prediction and Final score
Finally we made it!!!
Random Forest Regressor
Training Accuracy: 96.2% Accuracy
Testing Accuracy: 95.3% Accuracy
Support Vector Regressor
Training Accuracy: 96.2% Accuracy
Testing Accuracy: 95.8% Accuracy
Output & Conclusion
So both of the algorithms are gave same level of prediction accuracy. So I Hope all of You Like this blog. If you wanna say more about in this blog or wanna hiring me you can just contact me.
You can Ping me on these. Thank you all of you i’ll see you in the next blog. Bye take care all of you !!!








