{ "cells": [ { "cell_type": "code", "execution_count": 8, "id": "48a825f6", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Mobile_NameBattery_PowerProcessor_SpeedRAMInternal_StoragePixel_ResolutionNum_CoresWeightPrice
0sigma S+40002.3612819200004180700
1Sigma SX+45002.5825624000006190900
2Sigma SXMAX50002.812512300000082001200
3Sigma Pro30002.146415000004170500
4XS35002.4612818000004175600
\n", "
" ], "text/plain": [ " Mobile_Name Battery_Power Processor_Speed RAM Internal_Storage \\\n", "0 sigma S+ 4000 2.3 6 128 \n", "1 Sigma SX+ 4500 2.5 8 256 \n", "2 Sigma SXMAX 5000 2.8 12 512 \n", "3 Sigma Pro 3000 2.1 4 64 \n", "4 XS 3500 2.4 6 128 \n", "\n", " Pixel_Resolution Num_Cores Weight Price \n", "0 1920000 4 180 700 \n", "1 2400000 6 190 900 \n", "2 3000000 8 200 1200 \n", "3 1500000 4 170 500 \n", "4 1800000 4 175 600 " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.preprocessing import StandardScaler\n", "import numpy as np\n", "from sklearn.linear_model import LinearRegression\n", "import tkinter as tk\n", "from tkinter import messagebox\n", "from sklearn import metrics\n", "from sklearn.preprocessing import MinMaxScaler\n", "\n", "\n", "# Load dataset\n", "data = pd.read_csv(\"expanded_mobile_data.csv\")\n", "\n", "data.head()" ] }, { "cell_type": "code", "execution_count": 5, "id": "3605f4e2", "metadata": {}, "outputs": [], "source": [ "# Selecting features and target variable\n", "X = data[['Battery_Power', 'Processor_Speed', 'RAM', 'Internal_Storage', \n", " 'Pixel_Resolution', 'Num_Cores', 'Weight']]\n", "y = data['Price']\n", "\n", "# Splitting the data into training and testing sets\n", "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n", "\n", "# Creating the linear regression model\n", "model = LinearRegression()\n", "\n", "# Training the model\n", "model.fit(X_train, y_train)\n", "\n", "# Making predictions\n", "y_pred = model.predict(X_test)\n" ] }, { "cell_type": "code", "execution_count": 7, "id": "1d7a6b63", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-0.06666573691843936\n" ] } ], "source": [ "X = data.iloc[:, 1:-1]\n", "y = data['Price']\n", "# Split the data into training and testing sets\n", "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n", "\n", "\n", "regressor = LinearRegression()\n", "regressor.fit(X_train,y_train)\n", "r2_score = regressor.score(X_test,y_test)\n", "print(r2_score)\n", "\n" ] }, { "cell_type": "code", "execution_count": 15, "id": "c8171f01", "metadata": {}, "outputs": [], "source": [ "\n", "class MobilePricePredictor:\n", " def __init__(self, master):\n", " self.master = master\n", " self.master.title(\"Mobile Price Predictor\")\n", "\n", " self.battery_power_var = tk.StringVar()\n", " self.processor_speed_var = tk.StringVar()\n", " self.ram_var = tk.StringVar()\n", " self.internal_storage_var = tk.StringVar()\n", " self.pixel_resolution_var = tk.StringVar()\n", " self.num_cores_var = tk.StringVar()\n", " self.weight_var = tk.StringVar()\n", "\n", " self.current_page = 0\n", " self.phones_per_page = 10\n", "\n", " self.show_main_menu()\n", "\n", " def get_prediction(self):\n", " try:\n", " battery_power = float(self.battery_power_var.get())\n", " processor_speed = float(self.processor_speed_var.get())\n", " ram = int(self.ram_var.get())\n", " internal_storage = int(self.internal_storage_var.get())\n", " pixel_resolution = int(self.pixel_resolution_var.get())\n", " num_cores = int(self.num_cores_var.get())\n", " weight = float(self.weight_var.get())\n", "\n", " # Validation of inputs\n", " if not (3000 <= battery_power <= 6000):\n", " raise ValueError(\"Battery Power must be between 3000 and 6000 mAh.\")\n", " if not (2.0 <= processor_speed <= 3.5):\n", " raise ValueError(\"Processor Speed must be between 2.0 and 3.5 GHz.\")\n", " if not (4 <= ram <= 16):\n", " raise ValueError(\"RAM must be between 4 and 16 GB.\")\n", " if not (64 <= internal_storage <= 512):\n", " raise ValueError(\"Internal Storage must be between 64 and 512 GB.\")\n", " if not (1500000 <= pixel_resolution <= 4000000):\n", " raise ValueError(\"Pixel Resolution must be between 1500000 and 4000000.\")\n", " if not (4 <= num_cores <= 10):\n", " raise ValueError(\"Number of Cores must be between 4 and 10.\")\n", " if not (150 <= weight <= 250):\n", " raise ValueError(\"Weight must be between 150 and 250 grams.\")\n", "\n", " new_mobile = pd.DataFrame([{\n", " 'Battery_Power': battery_power,\n", " 'Processor_Speed': processor_speed,\n", " 'RAM': ram,\n", " 'Internal_Storage': internal_storage,\n", " 'Pixel_Resolution': pixel_resolution,\n", " 'Num_Cores': num_cores,\n", " 'Weight': weight\n", " }])\n", "\n", " predicted_price = model.predict(new_mobile)[0]\n", "\n", " # Recommend a phone based on the predicted price\n", " recommended_phone = data.iloc[(data['Price'] - predicted_price).abs().argsort()[:1]]\n", " phone_name = recommended_phone['Mobile_Name'].values[0]\n", " phone_price = recommended_phone['Price'].values[0]\n", "\n", " messagebox.showinfo(\"Prediction Result\", f\"The predicted price is: ${predicted_price:.2f}\\nRecommended Phone: {phone_name} (${phone_price})\")\n", " except ValueError as ve:\n", " messagebox.showerror(\"Invalid Input\", str(ve))\n", " except Exception as e:\n", " messagebox.showerror(\"Error\", f\"An unexpected error occurred: {str(e)}\")\n", "\n", " def show_all_phones(self):\n", " def display_page(page):\n", " for widget in self.master.winfo_children():\n", " widget.destroy()\n", "\n", " start_index = page * self.phones_per_page\n", " end_index = start_index + self.phones_per_page\n", " phones = data.iloc[start_index:end_index]\n", "\n", " tk.Label(self.master, text=\"Available Phones\", font=(\"Helvetica\", 16)).grid(row=0, column=0, columnspan=3, pady=10)\n", "\n", " for i, (_, phone) in enumerate(phones.iterrows(), start=1):\n", " tk.Label(self.master, text=f\"{phone['Mobile_Name']} - ${phone['Price']}\").grid(row=i, column=0, columnspan=3, pady=5)\n", "\n", " if start_index > 0:\n", " tk.Button(self.master, text=\"Previous\", command=lambda: display_page(page - 1)).grid(row=self.phones_per_page + 1, column=0, pady=20)\n", " if end_index < len(data):\n", " tk.Button(self.master, text=\"Next\", command=lambda: display_page(page + 1)).grid(row=self.phones_per_page + 1, column=2, pady=20)\n", "\n", " tk.Button(self.master, text=\"Back\", command=self.show_main_menu).grid(row=self.phones_per_page + 1, column=1, pady=20)\n", "\n", " display_page(self.current_page)\n", "\n", " \n", " def show_input_interface(self):\n", " for widget in self.master.winfo_children():\n", " widget.destroy()\n", "\n", " tk.Label(self.master, text=\"Enter Mobile Specifications\", font=(\"Helvetica\", 16)).grid(row=0, column=0, columnspan=2, pady=10)\n", "\n", " tk.Label(self.master, text=\"Battery Power (mAh, e.g., 3000-6000):\").grid(row=1, column=0, pady=5, sticky=tk.E)\n", " self.battery_power_var.set(\"\")\n", " tk.Entry(self.master, textvariable=self.battery_power_var).grid(row=1, column=1, pady=5)\n", "\n", " tk.Label(self.master, text=\"Processor Speed (GHz, e.g., 2.0-3.5):\").grid(row=2, column=0, pady=5, sticky=tk.E)\n", " self.processor_speed_var.set(\"\")\n", " tk.Entry(self.master, textvariable=self.processor_speed_var).grid(row=2, column=1, pady=5)\n", "\n", " tk.Label(self.master, text=\"RAM (GB, e.g., 4-16):\").grid(row=3, column=0, pady=5, sticky=tk.E)\n", " self.ram_var.set(\"\")\n", " tk.Entry(self.master, textvariable=self.ram_var).grid(row=3, column=1, pady=5)\n", "\n", " tk.Label(self.master, text=\"Internal Storage (GB, e.g., 64-512):\").grid(row=4, column=0, pady=5, sticky=tk.E)\n", " self.internal_storage_var.set(\"\")\n", " tk.Entry(self.master, textvariable=self.internal_storage_var).grid(row=4, column=1, pady=5)\n", "\n", " tk.Label(self.master, text=\"Pixel Resolution (e.g., 1500000-4000000):\").grid(row=5, column=0, pady=5, sticky=tk.E)\n", " self.pixel_resolution_var.set(\"\")\n", " tk.Entry(self.master, textvariable=self.pixel_resolution_var).grid(row=5, column=1, pady=5)\n", "\n", " tk.Label(self.master, text=\"Number of Cores (e.g., 4-10):\").grid(row=6, column=0, pady=5, sticky=tk.E)\n", " self.num_cores_var.set(\"\")\n", " tk.Entry(self.master, textvariable=self.num_cores_var).grid(row=6, column=1, pady=5)\n", "\n", " tk.Label(self.master, text=\"Weight (grams, e.g., 150-250):\").grid(row=7, column=0, pady=5, sticky=tk.E)\n", " self.weight_var.set(\"\")\n", " tk.Entry(self.master, textvariable=self.weight_var).grid(row=7, column=1, pady=5)\n", "\n", " tk.Button(self.master, text=\"Predict Price\", command=self.get_prediction).grid(row=8, column=0, pady=20)\n", " tk.Button(self.master, text=\"Back\", command=self.show_main_menu).grid(row=8, column=1, pady=20)\n", "\n", " def show_main_menu(self):\n", " for widget in self.master.winfo_children():\n", " widget.destroy()\n", "\n", " tk.Label(self.master, text=\"Mobile Price Predictor\", font=(\"Helvetica\", 16)).grid(row=0, column=0, columnspan=2, pady=10)\n", "\n", " tk.Button(self.master, text=\"Enter Mobile Specifications\", command=self.show_input_interface).grid(row=1, column=0, columnspan=2, pady=20)\n", " tk.Button(self.master, text=\"Display All Phones\", command=self.show_all_phones).grid(row=2, column=0, columnspan=2, pady=20)\n", " \n", "\n", "if __name__ == \"__main__\":\n", " root = tk.Tk()\n", " app = MobilePricePredictor(root)\n", " root.mainloop()\n" ] }, { "cell_type": "code", "execution_count": null, "id": "d39f0392", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "eda04d75", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" } }, "nbformat": 4, "nbformat_minor": 5 }