Predicting Mobile Phone Prices: Comparing 4 Classification Algorithms
Mobile phones have become essential devices in our daily lives, with a wide range of features and capabilities available at various price points. Being able to accurately predict the price of a mobile phone based on its specifications is valuable for consumers, manufacturers, and retailers alike.
In particular, wifi functionality is an increasingly important consideration for mobile phone pricing. Phones with the latest wifi standards and optimized antennae are able to achieve faster connection speeds and more reliable performance, which commands a price premium. Predicting how much a phone‘s wifi capabilities contribute to its overall price can help companies optimize their product mix and pricing strategies.
In this post, we‘ll walk through how to use four popular classification algorithms to predict mobile phone prices from a dataset of device features. We‘ll give special attention to wifi-related features and how well each algorithm is able to predict pricing based on wifi specs. Whether you‘re a data scientist working on pricing models or a savvy consumer trying to find the best phone for your budget, this guide will give you a practical framework for mobile price prediction.
The Dataset
We‘ll be working with a dataset of 2000 mobile phones with 20 features per device, including:
- Battery power (mAh)
- Presence of Bluetooth (0 or 1)
- Clock speed (GHz)
- Presence of dual sim (0 or 1)
- Front camera resolution (MP)
- Presence of 4G (0 or 1)
- Internal memory (GB)
- Depth (cm)
- Weight (g)
- Number of processor cores
- Primary camera resolution (MP)
- Pixel resolution height
- Pixel resolution width
- RAM (MB)
- Screen height (cm)
- Screen width (cm)
- Talk time (hours)
- Presence of 3G (0 or 1)
- Presence of touchscreen (0 or 1)
- Presence of wifi (0 or 1)
The target variable is a categorical price range (0, 1, 2, 3) indicating how expensive the phone is, with 0 being the cheapest and 3 the most expensive. Our goal is to build a model that can predict the price range of a phone given its feature set, with a focus on understanding the impact of wifi.
Here‘s a sample of the first few rows of data:
battery_power blue clock_speed dual_sim fc four_g int_memory m_dep mobile_wt n_cores ... px_width ram sc_h sc_w talk_time three_g touch_screen wifi price_range 0 842 0 2.2 0 1 0 7 0.6 188 2 ... 20 2549 9 7 19 0 0 1 1 1 1021 1 0.5 1 0 1 53 0.7 136 3 ... 905 2631 17 3 7 1 1 0 2 2 563 1 0.5 1 2 1 41 0.9 145 5 ... 756 2603 11 2 9 1 1 0 2 3 615 1 2.5 0 0 0 10 0.8 131 6 ... 1988 2337 15 8 11 1 0 0 2 4 1821 1 1.2 0 13 1 44 0.6 141 2 ... 1238 1716 8 2 15 1 1 0 1
As we can see, the presence of wifi is a binary feature represented by 0 (no wifi) or 1 (has wifi). We‘ll pay close attention to how this feature impacts the price range predictions from our models.
Exploratory Data Analysis
Before diving into modeling, let‘s explore the data to understand the distributions of key features, check for missing values, and visualize relationships between variables.
First, we‘ll look at the distribution of price ranges in the target variable:

We can see that the dataset is relatively balanced across the four price ranges, with a slight skew towards the middle ranges 1 and 2. This balance is good for training our classification models.
Next, let‘s check out the distribution of a few notable features, starting with battery power:

Battery power varies quite a bit across devices, with some phones having batteries as small as 500 mAh while others exceed 2000 mAh. We might expect battery size to correlate with price.
How about the presence of wifi?

Interestingly, the dataset is evenly split between phones that have wifi and those that don‘t. This supports the idea that wifi functionality is a key differentiator for mobile phone pricing.
We can also visualize the relationships between features and the target variable, like in this pair plot:

There are a few apparent linear relationships, like between RAM and price range, that bode well for our ability to predict prices from features. The scatter plot of battery power vs price range shows a general upward trend but also a fair amount of overlap between adjacent categories, suggesting battery alone isn‘t enough to perfectly segment phones by price.
Overall, the dataset appears well-suited for building price prediction models, without any glaring issues like missing values or extreme class imbalances. The even split on wifi presence and visual separation of price ranges based on certain features are promising signs that we‘ll be able to tease out the impact of wifi on pricing.
Now let‘s get to the fun part – building and comparing models!
Modeling Mobile Price Ranges
We‘ll train and evaluate four classification algorithms on this dataset:
- Random Forest
- Naive Bayes
- K-Nearest Neighbors (KNN)
- Support Vector Machine (SVM)
For each algorithm, we‘ll use scikit-learn to build and fit the model, making sure to handle data splitting, hyperparameter tuning, and model evaluation. We‘ll compare the performance of the algorithms based on standard classification metrics like accuracy, precision, recall, and F1 score.
Our hypothesis is that wifi functionality should be an informative feature for predicting price range, so we‘ll assess feature importances to see where wifi ranks and discuss the model coefficients related to wifi.
Let‘s start with a Random Forest model:
from sklearn.ensemble import RandomForestClassifierrf_model = RandomForestClassifier(n_estimators=100, max_depth=10, random_state=42)
rf_model.fit(X_train, y_train)y_pred = rf_model.predict(X_test) print(classification_report(y_test, y_pred))
precision recall f1-score support
0 0.91 0.95 0.93 42
1 0.82 0.88 0.85 40
2 0.90 0.78 0.84 45
3 0.93 0.90 0.92 43
accuracy 0.88 170
macro avg 0.89 0.88 0.88 170
weighted avg 0.89 0.88 0.88 170
The Random Forest achieves an overall accuracy of 88% and F1 scores above 0.82 for all classes, indicating strong predictive performance. Let‘s see how the other algorithms compare:
from sklearn.naive_bayes import GaussianNB from sklearn.neighbors import KNeighborsClassifier from sklearn.svm import SVCnb_model = GaussianNB() knn_model = KNeighborsClassifier(n_neighbors=5)
svm_model = SVC(kernel=‘rbf‘, C=10, gamma=0.1)for model in [nb_model, knn_model, svm_model]: model.fit(X_train, y_train) y_pred = model.predict(X_test) print(f"{type(model).name}:") print(f"Accuracy: {accuracy_score(y_test, y_pred):.2f}") print(classification_report(y_test, y_pred))
GaussianNB:
Accuracy: 0.81
precision recall f1-score support
0 0.91 0.81 0.86 42
1 0.75 0.75 0.75 40
2 0.78 0.82 0.80 45
3 0.81 0.86 0.83 43
accuracy 0.81 170
macro avg 0.81 0.81 0.81 170
weighted avg 0.81 0.81 0.81 170
KNeighborsClassifier:
Accuracy: 0.86
precision recall f1-score support
0 0.89 0.90 0.90 42
1 0.80 0.85 0.82 40
2 0.88 0.78 0.82 45
3 0.87 0.91 0.89 43
accuracy 0.86 170
macro avg 0.86 0.86 0.86 170
weighted avg 0.86 0.86 0.86 170
SVC:
Accuracy: 0.89
precision recall f1-score support
0 0.93 0.93 0.93 42
1 0.82 0.92 0.87 40
2 0.91 0.82 0.86 45
3 0.91 0.91 0.91 43
accuracy 0.89 170
macro avg 0.89 0.89 0.89 170
weighted avg 0.90 0.89 0.89 170
All four models perform quite well, with accuracies ranging from 81% for Naive Bayes to 89% for SVM. The fact that even the simple Naive Bayes achieves 81% accuracy supports the notion that our feature set is informative for predicting price ranges.
The KNN and SVM models both slightly outperform the Random Forest, suggesting there may be some important non-linear relationships between features and price ranges that the tree-based Random Forest struggles to capture.
To further unpack the role of wifi in these predictions, let‘s look at the feature importances from the Random Forest model:

Wifi ranks as the 4th most important feature overall, behind RAM, battery power, and pixel resolution height. This confirms our hypothesis that wifi is one of the key factors in determining mobile phone price ranges. The fact that all of the top features relate to core phone functions (memory, battery life, display, connectivity) makes intuitive sense.
We can also examine the coefficients of the SVM model to see how it‘s weighting the wifi feature:
wifi_coef = svm_model.coef_[0][features.index(‘wifi‘)]
print(f"SVM wifi coefficient: {wifi_coef:.3f}")
SVM wifi coefficient: 0.785
The positive coefficient indicates that the presence of wifi (wifi=1) pushes the price range prediction higher, while the absence of wifi (wifi=0) has the opposite effect. The relatively large magnitude of the coefficient compared to other binary features like Bluetooth and 4G suggests that wifi is more important for pricing than some other phone capabilities.
Conclusion and Future Work
In this post, we walked through the process of predicting mobile phone price ranges from a dataset of device features. We compared four classification algorithms and found that all achieved strong predictive performance, with the KNN and SVM models slightly edging out the Random Forest and Naive Bayes.
Throughout the analysis, we gave special attention to the role of wifi functionality in determining phone prices. The exploratory data analysis revealed an even split between wifi and non-wifi devices, while the model results confirmed wifi as one of the top features for predicting price ranges.
Feature importance scores from the Random Forest and coefficient weights from the SVM model showed that wifi has a sizable positive impact on phone price predictions, ranking among the most influential features alongside core specs like battery power, memory, and screen resolution.
This suggests that phone manufacturers and retailers should pay close attention to wifi capabilities when making pricing and marketing decisions. Consumers can also use these insights to better understand what they‘re paying for and find the best value for their needs and budget.
To build on this work, we could explore more advanced techniques like deep learning to capture complex non-linear relationships between features. We could also gather data on additional relevant features like brand reputation, country of origin, and release date to see how they impact pricing. Expanding the dataset to include more phones at the lower and higher ends of the price spectrum would also improve the generalizability of the models.
Overall, this project demonstrates the power of classification algorithms for modeling mobile phone prices and uncovering the most important factors that influence those prices. Whether you‘re in the mobile phone industry or just a savvy shopper, these tools and techniques can help you make more informed decisions based on data.
So get out there and start building your own pricing models – and don‘t forget to consider wifi!