|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 |
| - "execution_count": 1, |
| 5 | + "execution_count": null, |
6 | 6 | "metadata": {},
|
7 |
| - "outputs": [ |
8 |
| - { |
9 |
| - "name": "stdout", |
10 |
| - "output_type": "stream", |
11 |
| - "text": [ |
12 |
| - "Silhouette Score: 0.057004055728191866\n", |
13 |
| - "\n", |
14 |
| - "Cluster 0:\n", |
15 |
| - "Acer ED322QR 31.5 Inch (80.01 cm) Full HD Curved VA Backlit LED Monitor I 144Hz Refresh Rate I Zero Frame I AMD Free Sync I Eye Care Features I Stereo Speakers\n", |
16 |
| - "--------------------------------------------------\n", |
17 |
| - "HP 3.1 USB HP 32 GB Flash Drive\n", |
18 |
| - "--------------------------------------------------\n", |
19 |
| - "Logitech MX Anywhere 3 Compact Performance Mouse – Wireless, Magnetic Scrolling, Ergonomic, 4000DPI Sensor, Custom Buttons, USB-C, Bluetooth, Apple Mac, iPad, Windows PC, Linux, Chrome - Graphite\n", |
20 |
| - "--------------------------------------------------\n", |
21 |
| - "SanDisk Cruzer Blade 32GB USB Flash Drive\n", |
22 |
| - "--------------------------------------------------\n", |
23 |
| - "APLT-Portable Slim Wireless Mouse for Laptops 2.4Ghz Silent Wireless Optical Mouse for Laptop, Desktop ( White)\n", |
24 |
| - "--------------------------------------------------\n", |
25 |
| - "\n", |
26 |
| - "Cluster 1:\n", |
27 |
| - "Zebronics Zeb-Corolla In Ear Wired Earphone with Mic, 3.5mm Jack, 1.2 Meter Cable, Multi Function Button\n", |
28 |
| - "--------------------------------------------------\n", |
29 |
| - "MINISO We Bare Bears in-Ear Wired Headphones with Microphone, Comfortable Earbuds Cute Earphones for Mobile Smartphones Apple Xiaomi Realme Oppo Samsung and More - Brown\n", |
30 |
| - "--------------------------------------------------\n", |
31 |
| - "pTron Tangent Evo with 14Hrs Playback, Bluetooth 5.0 Wireless Headphones with Deep Bass, IPX4 Water Resistance, Ergonomic & Snug-fit, Voice Assistance, Magnetic Earbuds & Built-in HD Mic (Black)\n", |
32 |
| - "--------------------------------------------------\n", |
33 |
| - "Ambrane Dots 38 True Wireless Earbuds TWS with Pure HD Bass, 16H Playtime, IPX4 Waterproof, Responsive Touch Sensors for Multifunctions, Compact Type-C Charging Case (Green), Normal\n", |
34 |
| - "--------------------------------------------------\n", |
35 |
| - "Peripage A6 203dpi Thermal Label Printer Inkless Pocket Printer Bluetooth Connection Office Assistant/Life Helper DIY Printing Travel Recorder for iOS/Android/Windows\n", |
36 |
| - "--------------------------------------------------\n", |
37 |
| - "\n", |
38 |
| - "Cluster 2:\n", |
39 |
| - "AVITA LIBER V NS14A8INF542-CS Thin and Light 14 inch (35.56cm) Laptop( Intel Core i5-10210U/ 8GB/256GB SSD /Win 10 Home/ Backlit Keyboard/ Fingerprint Sensor/ MSO 365) 1.28kg, Cloud Silver\n", |
40 |
| - "--------------------------------------------------\n", |
41 |
| - "(Renewed) HP ProBook 7th Gen Core i5 Laptop, 16 GB RAM, 240GB NVME SSD, Intel HD Graphics, 15.6 inch (39.62 cms) FHD Screen, Win 10, MS Office, Backlit Keyboard, Fingerprint sensor, Black\n", |
42 |
| - "--------------------------------------------------\n", |
43 |
| - "CHIST Gaming Desktop Intel Core i5 8GB,GT 710 2GB Graphic Card, 19 Full HD Monitor, Keyboard Mouse, Wi-Fi Ready to Play (120GB SSD 1TB HDD)\n", |
44 |
| - "--------------------------------------------------\n", |
45 |
| - "(Renewed) Lenovo ThinkCenter M58 19-inch (48.26 cm) Desktop (Intel Core2 Duo 4 GB 500 GB HDD Windows 7 Professional MS Office), Black\n", |
46 |
| - "--------------------------------------------------\n", |
47 |
| - "Lenovo ThinkBook 15 Intel 11th Gen Core i5 15.6\" (39.62 cm) FHD IPS 300 nits Antiglare 100% sRGB Thin and Light Laptop (16GB/1TB HDD+128GB SSD/Windows 10/MS Office/Mineral Grey/1.7 Kg), 20VEA0HKIH\n", |
48 |
| - "--------------------------------------------------\n", |
49 |
| - "\n", |
50 |
| - "Cluster 3:\n", |
51 |
| - "Mi 80 cm (32 inches) Horizon Edition HD Ready Android Smart LED TV 4A|L32M6-EI (Grey)\n", |
52 |
| - "--------------------------------------------------\n", |
53 |
| - "Foxsky 127 cm (50 inches) 4K Ultra HD Smart LED TV 50FS-VS (Black) (2021 Model) | With Voice Assistant\n", |
54 |
| - "--------------------------------------------------\n", |
55 |
| - "Kevin 80 cm (32 Inches) HD Ready Smart LED TV KN32A (Black) (2021 Model) | With Alexa Built-in\n", |
56 |
| - "--------------------------------------------------\n", |
57 |
| - "Samsung 108 cm (43 inches) 4K Ultra HD Smart QLED TV QA43Q60AAKLXL (Black) (2021 Model)\n", |
58 |
| - "--------------------------------------------------\n", |
59 |
| - "eAirtec 60 cm (24 Inches) HD Ready Smart Android LED TV 24DJSmart (Black) (2021 Model)\n", |
60 |
| - "--------------------------------------------------\n", |
61 |
| - "\n", |
62 |
| - "Cluster 4:\n", |
63 |
| - "Ovista- 10000mAH Digital Display Power Bank with inbuilt 4 in 1 Cable USB Input Port with Fast Charging 10000mAh Slim Power Bank with 5V/2A Fast Charging (Model-PRB035)- Black\n", |
64 |
| - "--------------------------------------------------\n", |
65 |
| - "Ambrane 5000mAh Li-Polymer Powerbank with Fast Charging & Compact Size (PP-501, Pink)\n", |
66 |
| - "--------------------------------------------------\n", |
67 |
| - "URBN 20000mAh Li-Polymer Ultra Compact Type-C Power Bank with 12W Fast Charge, Type C & Micro Input (Black)\n", |
68 |
| - "--------------------------------------------------\n", |
69 |
| - "Conekt 10000mAh Li-Polymer Powerbank Zeal Proton Pro (White)\n", |
70 |
| - "--------------------------------------------------\n", |
71 |
| - "Zeal PL-10000 10400mAh Power Bank\n", |
72 |
| - "--------------------------------------------------\n" |
73 |
| - ] |
74 |
| - } |
75 |
| - ], |
| 7 | + "outputs": [], |
76 | 8 | "source": [
|
77 | 9 | "\n",
|
78 | 10 | "import pandas as pd\n",
|
79 | 11 | "from sklearn.feature_extraction.text import TfidfVectorizer\n",
|
80 | 12 | "from sklearn.cluster import KMeans\n",
|
81 | 13 | "from sklearn.metrics import silhouette_score\n",
|
| 14 | + "from nltk.sentiment import SentimentIntensityAnalyzer\n", |
| 15 | + "\n", |
| 16 | + "# Load NLTK's sentiment analyzer\n", |
| 17 | + "sid = SentimentIntensityAnalyzer()\n", |
82 | 18 | "\n",
|
83 | 19 | "data = pd.read_csv('Product listing.csv')\n",
|
84 | 20 | "\n",
|
|
108 | 44 | "# Assign cluster labels to each review\n",
|
109 | 45 | "data['cluster_label'] = kmeans.labels_\n",
|
110 | 46 | "\n",
|
| 47 | + "# Sentiment Analysis\n", |
| 48 | + "def get_sentiment(text):\n", |
| 49 | + " # NLTK's sentiment analyzer\n", |
| 50 | + " sentiment_scores = sid.polarity_scores(text)\n", |
| 51 | + " # Classify sentiment based on compound score\n", |
| 52 | + " if sentiment_scores['compound'] >= 0.05:\n", |
| 53 | + " return 'Positive'\n", |
| 54 | + " elif sentiment_scores['compound'] <= -0.05:\n", |
| 55 | + " return 'Negative'\n", |
| 56 | + " else:\n", |
| 57 | + " return 'Neutral'\n", |
| 58 | + " \n", |
| 59 | + "data['sentiment'] = data['clean_text'].apply(get_sentiment)\n", |
| 60 | + "\n", |
| 61 | + "\n", |
111 | 62 | "# Evaluate clustering using silhouette score\n",
|
112 | 63 | "silhouette_avg = silhouette_score(tfidf_matrix, kmeans.labels_)\n",
|
113 | 64 | "print(f\"Silhouette Score: {silhouette_avg}\")\n",
|
|
118 | 69 | " print(f\"\\nCluster {cluster_id}:\")\n",
|
119 | 70 | " for index, row in cluster_samples.iterrows():\n",
|
120 | 71 | " print(row['product'])\n",
|
| 72 | + " print(\"Sentiment:\", row['sentiment'])\n", |
121 | 73 | " print('-' * 50)\n",
|
122 | 74 | "\n",
|
123 | 75 | "# You can further analyze the clusters and refine the process as needed\n"
|
|
126 | 78 | ],
|
127 | 79 | "metadata": {
|
128 | 80 | "kernelspec": {
|
129 |
| - "display_name": "Python 3", |
| 81 | + "display_name": "Python 3 (ipykernel)", |
130 | 82 | "language": "python",
|
131 | 83 | "name": "python3"
|
132 | 84 | },
|
|
140 | 92 | "name": "python",
|
141 | 93 | "nbconvert_exporter": "python",
|
142 | 94 | "pygments_lexer": "ipython3",
|
143 |
| - "version": "3.11.9" |
| 95 | + "version": "3.11.4" |
144 | 96 | }
|
145 | 97 | },
|
146 | 98 | "nbformat": 4,
|
|
0 commit comments