hongaik commited on
Commit
2bbae19
·
1 Parent(s): af4a8bf

added touchpoint

Browse files
.ipynb_checkpoints/Untitled-checkpoint.ipynb DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "cells": [],
3
- "metadata": {},
4
- "nbformat": 4,
5
- "nbformat_minor": 5
6
- }
 
 
 
 
 
 
 
Untitled.ipynb DELETED
@@ -1,110 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": 16,
6
- "id": "8e91c310-bc69-4a28-9197-e180aaaa491f",
7
- "metadata": {},
8
- "outputs": [
9
- {
10
- "name": "stdout",
11
- "output_type": "stream",
12
- "text": [
13
- "utils imported!\n"
14
- ]
15
- }
16
- ],
17
- "source": [
18
- "import re\n",
19
- "import pickle\n",
20
- "import numpy as np\n",
21
- "import pandas as pd\n",
22
- "\n",
23
- "\n",
24
- "tfidf = pickle.load(open('models/tfidf.sav', 'rb'))\n",
25
- "svc_sentiment = pickle.load(open('models/sentiment_model.sav', 'rb'))\n",
26
- "tfidf_sentiment = pickle.load(open('models/tfidf_sentiment.sav', 'rb'))\n",
27
- "svc = pickle.load(open('models/svc_model.sav', 'rb'))\n",
28
- "\n",
29
- "labels = [\n",
30
- " 'Product quality', 'Knowledge',\n",
31
- " 'Appointment', 'Service etiquette', 'Waiting time',\n",
32
- " 'Repair speed', 'Repair cost', 'Repair quality', 'Warranty',\n",
33
- " 'Product replacement', 'Loan sets']\n",
34
- "\n",
35
- "sample_file = pd.read_csv('sample.csv').to_csv(index=False).encode('utf-8')\n",
36
- "\n",
37
- "print('utils imported!')\n",
38
- "\n",
39
- "def get_single_prediction(text):\n",
40
- " \n",
41
- " # manipulate data into a format that we pass to our model\n",
42
- " text = text.lower().strip() #lower case\n",
43
- " print(list(text))\n",
44
- " # Vectorise text and store in new dataframe. Sentence vector = average of word vectors\n",
45
- " text_vectors = tfidf.transform([text])\n",
46
- " print(text_vectors.shape)\n",
47
- " # Make topic predictions\n",
48
- " results = svc.predict_proba(text_vectors).squeeze().round(2)\n",
49
- " print(results.shape)\n",
50
- "\n",
51
- " pred_prob = pd.DataFrame({'topic': labels, 'probability': results}).sort_values('probability', ascending=True)\n",
52
- "\n",
53
- " # Make sentiment predictions\n",
54
- " text_vectors_sentiment = tfidf_sentiment.transform(list(text))\n",
55
- "\n",
56
- " results_sentiment = svc_sentiment.predict_proba(text_vectors).squeeze().round(2)\n",
57
- " pred_prob_sentiment = pd.DataFrame({'sentiment': ['Negative', 'Positive'], 'probability': results_sentiment}).sort_values('probability', ascending=True)"
58
- ]
59
- },
60
- {
61
- "cell_type": "code",
62
- "execution_count": 17,
63
- "id": "b940cb16-c287-4fef-accc-fa54f20c3864",
64
- "metadata": {},
65
- "outputs": [
66
- {
67
- "name": "stdout",
68
- "output_type": "stream",
69
- "text": [
70
- "['h', 'e', 'l', 'l', 'o']\n",
71
- "(1, 500)\n",
72
- "(11,)\n"
73
- ]
74
- }
75
- ],
76
- "source": [
77
- "get_single_prediction('hello')"
78
- ]
79
- },
80
- {
81
- "cell_type": "code",
82
- "execution_count": null,
83
- "id": "1f68efcf-479d-41de-be1e-e94d00b58fab",
84
- "metadata": {},
85
- "outputs": [],
86
- "source": []
87
- }
88
- ],
89
- "metadata": {
90
- "kernelspec": {
91
- "display_name": "Python 3",
92
- "language": "python",
93
- "name": "python3"
94
- },
95
- "language_info": {
96
- "codemirror_mode": {
97
- "name": "ipython",
98
- "version": 3
99
- },
100
- "file_extension": ".py",
101
- "mimetype": "text/x-python",
102
- "name": "python",
103
- "nbconvert_exporter": "python",
104
- "pygments_lexer": "ipython3",
105
- "version": "3.8.8"
106
- }
107
- },
108
- "nbformat": 4,
109
- "nbformat_minor": 5
110
- }