View on GitHub

Sahil Patra

Download this project as a .zip file Download this project as a tar.gz file

Mobile-Price-Prediction

The objective was to build a model that helps in predicting the price segment of a phone by analyzing its configuration.

Table of Contents


About the Project

Smartphone manufacturers and retailers often want to price their products based on features that matter most to customers. This project aims to build a classification model to predict the price range of mobile phones based on technical specifications. The dataset includes features like battery power, processor speed, memory, connectivity features, screen size, and more. The target variable price_range is categorized into four classes: low (0), medium (1), high (2), and very high (3).


Tools Used


Dataset


Steps Followed

  1. Data Preprocessing
    • Separated features (X) and target (y)
    • Scaled the features using StandardScaler
    • One-hot encoded the target variable for multi-class classification
  2. Train-Test Split
    • Used train_test_split with stratified sampling to maintain class balance
    • Split: 80% training, 20% testing
  3. Model Architecture
    • Input layer with number of features = 20
    • Hidden layers:
      • Dense(128) → ReLU
      • Dropout(0.3) to prevent overfitting
      • Dense(64) → ReLU
    • Output layer: Dense(4) with softmax activation (for 4 price categories)
  4. Compilation
    • Optimizer: Adam
    • Loss: categorical_crossentropy
    • Metrics: Accuracy
  5. Training
    • 20 epochs, batch size 32
    • 20% of training data used for validation
  6. Evaluation
    • Evaluated on test set accuracy
    • Generated classification report to assess performance on each price class.

Executive Summary

In this machine learning project, a multi-class classification model was developed to predict mobile phone price ranges based on technical specifications such as RAM, battery capacity, processor speed, screen dimensions, and connectivity features. The model achieved high classification accuracy and maintained a strong balance across all four price categories (low, medium, high, very high).

The classification report revealed excellent precision, recall, and F1-score across the board, indicating the model’s robustness in correctly identifying each class without bias or overfitting. These results affirm that the selected features and modeling approach are well-suited for price prediction tasks in retail and e-commerce decision-making scenarios.


Technical Process

Importing the necessary libraries

import pandas as pd
import numpy as np
import tensorflow as tf
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import classification_report, confusion_matrix
import matplotlib.pyplot as plt

Loading the Dataset

df = pd.read_csv("dataset.csv")

Separate Features and Target

y = df['price_range']
X = df.drop('price_range', axis=1)

Scaling the feature

scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

# Creating one-hot encoded target
y_encoded = tf.keras.utils.to_categorical(y, num_classes=4)

Train-Test Split

X_train, X_test, y_train, y_test = train_test_split(
    X_scaled, y_encoded, test_size=0.2, random_state=42, stratify=y
)

Build the Neural Network Model

inputs = tf.keras.Input(shape=(X_train.shape[1],))

x = tf.keras.layers.Dense(128, activation='relu')(inputs)
x = tf.keras.layers.Dropout(0.3)(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)
outputs = tf.keras.layers.Dense(4, activation='softmax')(x)

Compile the Model

model.compile(
    optimizer='adam',
    loss='categorical_crossentropy',
    metrics=['accuracy']
)

Train the Model

history = model.fit(
    X_train, y_train,
    epochs=20,
    batch_size=32,
    validation_split=0.2
)

Evaluate the Model

loss, accuracy = model.evaluate(X_test, y_test)
print(f"Test Accuracy: {accuracy:.2f}")

y_pred_probs = model.predict(X_test)
y_pred = np.argmax(y_pred_probs, axis=1)
y_true = np.argmax(y_test, axis=1)
print(classification_report(y_true, y_pred))

page

Visualizing the model accuracy over epochs

plt.plot(history.history['accuracy'], label='train accuracy')
plt.plot(history.history['val_accuracy'], label='val accuracy')
plt.title('Model Accuracy Over Epochs')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.legend()
plt.show()

page


Contact

Sahil Patra
LinkedIn: Sahil Patra
Email: sahilpatra1004@gmail.com
Ph no.: +91 7735367833 —

Thank you for checking out this project!