Commit 66862e81 authored by Boinapalli Kalyani's avatar Boinapalli Kalyani
Browse files

Upload New File

parent 5b170e7d
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"data = pd.read_csv('amazonfinal12.csv', delimiter = ',')\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Review</th>\n",
" <th>id</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>So there is no way for me to plug it in here i...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Good case, Excellent value.</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Great for the jawbone.</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Tied to charger for conversations lasting more...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>The mic is great.</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>I have to jiggle the plug to get it to line up...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>If you have several dozen or several hundred c...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>If you are Razr owner...you must have this!</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Needless to say, I wasted my money.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>What a waste of money and time!.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>And the sound quality is great.</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>He was very impressed when going from the orig...</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>If the two were seperated by a mere 5+ ft I st...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>Very good quality though</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>The design is very odd, as the ear \"clip\" is n...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>Highly recommend for any one who has a blue to...</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>I advise EVERYONE DO NOT BE FOOLED!</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>So Far So Good!.</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>Works great!.</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>It clicks into place in a way that makes you w...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>I went on Motorola's website and followed all ...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>I bought this to use with my Kindle Fire and a...</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>The commercials are the most misleading.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>I have yet to run this new battery below two b...</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>I bought it for my mother and she had a proble...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>Great Pocket PC / phone combination.</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>I've owned this phone for 7 months now and can...</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>I didn't think that the instructions provided ...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>People couldnt hear me talk and I had to pull ...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>Doesn't hold charge.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>970</th>\n",
" <td>I plugged it in only to find out not a darn th...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>971</th>\n",
" <td>Excellent product.</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>972</th>\n",
" <td>Earbud piece breaks easily.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>973</th>\n",
" <td>Lousy product.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>974</th>\n",
" <td>This phone tries very hard to do everything bu...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>975</th>\n",
" <td>It is the best charger I have seen on the mark...</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>976</th>\n",
" <td>SWEETEST PHONE!!!</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>977</th>\n",
" <td>:-)Oh, the charger seems to work fine.</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>978</th>\n",
" <td>It fits so securely that the ear hook does not...</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>979</th>\n",
" <td>Not enough volume.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>980</th>\n",
" <td>Echo Problem....Very unsatisfactory</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>981</th>\n",
" <td>you could only take 2 videos at a time and the...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>982</th>\n",
" <td>don't waste your money.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>983</th>\n",
" <td>I am going to have to be the first to negative...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>984</th>\n",
" <td>Adapter does not provide enough charging current.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>985</th>\n",
" <td>There was so much hype over this phone that I ...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>986</th>\n",
" <td>You also cannot take pictures with it in the c...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>987</th>\n",
" <td>Phone falls out easily.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>988</th>\n",
" <td>It didn't work, people can not hear me when I ...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>989</th>\n",
" <td>The text messaging feature is really tricky to...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>990</th>\n",
" <td>I'm really disappointed all I have now is a ch...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>991</th>\n",
" <td>Painful on the ear.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>992</th>\n",
" <td>Lasted one day and then blew up.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>993</th>\n",
" <td>disappointed.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>994</th>\n",
" <td>Kind of flops around.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>995</th>\n",
" <td>The screen does get smudged easily because it ...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>996</th>\n",
" <td>What a piece of junk.. I lose more calls on th...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>997</th>\n",
" <td>Item Does Not Match Picture.</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>998</th>\n",
" <td>The only thing that disappoint me is the infra...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>999</th>\n",
" <td>You can not answer calls with the unit, never ...</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>1000 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" Review id\n",
"0 So there is no way for me to plug it in here i... 0\n",
"1 Good case, Excellent value. 1\n",
"2 Great for the jawbone. 1\n",
"3 Tied to charger for conversations lasting more... 0\n",
"4 The mic is great. 1\n",
"5 I have to jiggle the plug to get it to line up... 0\n",
"6 If you have several dozen or several hundred c... 0\n",
"7 If you are Razr owner...you must have this! 1\n",
"8 Needless to say, I wasted my money. 0\n",
"9 What a waste of money and time!. 0\n",
"10 And the sound quality is great. 1\n",
"11 He was very impressed when going from the orig... 1\n",
"12 If the two were seperated by a mere 5+ ft I st... 0\n",
"13 Very good quality though 1\n",
"14 The design is very odd, as the ear \"clip\" is n... 0\n",
"15 Highly recommend for any one who has a blue to... 1\n",
"16 I advise EVERYONE DO NOT BE FOOLED! 0\n",
"17 So Far So Good!. 1\n",
"18 Works great!. 1\n",
"19 It clicks into place in a way that makes you w... 0\n",
"20 I went on Motorola's website and followed all ... 0\n",
"21 I bought this to use with my Kindle Fire and a... 1\n",
"22 The commercials are the most misleading. 0\n",
"23 I have yet to run this new battery below two b... 1\n",
"24 I bought it for my mother and she had a proble... 0\n",
"25 Great Pocket PC / phone combination. 1\n",
"26 I've owned this phone for 7 months now and can... 1\n",
"27 I didn't think that the instructions provided ... 0\n",
"28 People couldnt hear me talk and I had to pull ... 0\n",
"29 Doesn't hold charge. 0\n",
".. ... ..\n",
"970 I plugged it in only to find out not a darn th... 0\n",
"971 Excellent product. 1\n",
"972 Earbud piece breaks easily. 0\n",
"973 Lousy product. 0\n",
"974 This phone tries very hard to do everything bu... 0\n",
"975 It is the best charger I have seen on the mark... 1\n",
"976 SWEETEST PHONE!!! 1\n",
"977 :-)Oh, the charger seems to work fine. 1\n",
"978 It fits so securely that the ear hook does not... 1\n",
"979 Not enough volume. 0\n",
"980 Echo Problem....Very unsatisfactory 0\n",
"981 you could only take 2 videos at a time and the... 0\n",
"982 don't waste your money. 0\n",
"983 I am going to have to be the first to negative... 0\n",
"984 Adapter does not provide enough charging current. 0\n",
"985 There was so much hype over this phone that I ... 0\n",
"986 You also cannot take pictures with it in the c... 0\n",
"987 Phone falls out easily. 0\n",
"988 It didn't work, people can not hear me when I ... 0\n",
"989 The text messaging feature is really tricky to... 0\n",
"990 I'm really disappointed all I have now is a ch... 0\n",
"991 Painful on the ear. 0\n",
"992 Lasted one day and then blew up. 0\n",
"993 disappointed. 0\n",
"994 Kind of flops around. 0\n",
"995 The screen does get smudged easily because it ... 0\n",
"996 What a piece of junk.. I lose more calls on th... 0\n",
"997 Item Does Not Match Picture. 0\n",
"998 The only thing that disappoint me is the infra... 0\n",
"999 You can not answer calls with the unit, never ... 0\n",
"\n",
"[1000 rows x 2 columns]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split\n",
"from sklearn.feature_extraction.text import CountVectorizer\n",
"from sklearn.metrics import accuracy_score\n",
"import nltk\n",
"\n",
"stop_words=nltk.corpus.stopwords.words('english')\n",
"stop_words=list(np.setdiff1d(stop_words,['not']))\n",
"junk_words=[]\n",
"stop_words.extend(junk_words)\n",
"stemmer=nltk.PorterStemmer()\n",
"docs=data['Review'].fillna('').str.lower().str.replace('[^a-z ]','')\n",
"docs_clean=docs.apply(lambda v:' '.join([stemmer.stem(word) for word in v.split(' ') if word not in stop_words]))\n",
"\n",
"train,test=train_test_split(docs_clean,test_size=0.2,random_state=100)\n",
"\n",
"cv=CountVectorizer()\n",
"cv.fit(train)\n",
"train_x=cv.transform(train)\n",
"test_x=cv.transform(test)\n",
"\n",
"train_y=data.loc[train.index]['id']\n",
"test_y=data.loc[test.index]['id']"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(800, 1249)\n",
"(200, 1249)\n",
"(800,)\n",
"(200,)\n"
]
}
],
"source": [
"print(train_x.shape)\n",
"print(test_x.shape)\n",
"print(train_y.shape)\n",
"print(test_y.shape)"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"83.0\n"
]
}
],
"source": [
"# Logistic Model\n",
"from sklearn.linear_model import LogisticRegression\n",
"lr=LogisticRegression()\n",
"lr.fit(train_x,train_y)\n",
"pred_class=lr.predict(test_x)\n",
"lr_ac=accuracy_score(test_y,pred_class)\n",
"print(lr_ac*100)"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"81.5\n"
]
}
],
"source": [
"# Bagging Model\n",
"\n",
"from sklearn.ensemble import RandomForestClassifier\n",
"bagging_model=RandomForestClassifier(n_estimators=300,random_state=100)\n",
"bagging_model.fit(train_x,train_y)\n",
"pred_class=bagging_model.predict(test_x)\n",
"bg_acc=accuracy_score(test_y,pred_class)\n",
"print(bg_acc*100)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.15+"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment