-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsharktankindia.py
More file actions
440 lines (345 loc) · 16 KB
/
Copy pathsharktankindia.py
File metadata and controls
440 lines (345 loc) · 16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import nltk
from nltk.corpus import stopwords
from nltk import word_tokenize
from nltk.stem import WordNetLemmatizer
from nltk.corpus import wordnet
import matplotlib.pyplot as plt
import seaborn as sns
from nltk import FreqDist
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix, accuracy_score
from sklearn.metrics import roc_auc_score
import streamlit as st
from streamlit_option_menu import option_menu
import plotly.express as px
import time
import base64
def shark(user_sentence):
df1 = pd.read_excel('SharkTankIndiaS02.xlsx')
df=df1[["Idea","Deal"]].copy()
df["deal/no deal"]=df["Deal"].copy()
df['deal/no deal']=df['deal/no deal'].apply(lambda x: 'Deal' if x != 'No Deal' else x)
df['deal in binary']=df['deal/no deal'].apply(lambda x: 1 if x != 'No Deal' else x)
df["deal in binary"] = df["deal in binary"].replace(['No Deal'],[0])
# Replacing punctuations with space
df['Idea_processed'] = df['Idea'].str.replace("[^a-zA-Z0-9]", " ")
df['Idea_processed'] = df['Idea_processed'].astype(str)
df['Idea_processed'] = df['Idea_processed'].apply(lambda row: ' '.join([word for word in row.split() if len(word)>2]))
# make entire text lowercase
df['Idea_processed'] = [row.lower() for row in df['Idea_processed']]
# Removing Stopwords Begin
import nltk
nltk.download('punkt')
nltk.download('stopwords')
from nltk.corpus import stopwords
from nltk import word_tokenize
stop_words = stopwords.words('english') # extracting all the stop words in english language and storing it in a variable called stop_words -> set
# Making custom list of words to be removed
add_words = ['brand','company']
# Adding to the list of words
stop_words.extend(add_words)
# Function to remove stop words
def remove_stopwords(rev):
# iNPUT : IT WILL TAKE ROW/REVIEW AS AN INPUT
# take the paragraph, break into words, check if the word is a stop word, remove if stop word, combine the words into a para again
review_tokenized = word_tokenize(rev)
rev_new = " ".join([i for i in review_tokenized if i not in stop_words])
return rev_new
# Removing stopwords
df['Idea_processed'] = [remove_stopwords(r) for r in df['Idea_processed']]
# Begin Lemmatization
nltk.download('wordnet')
nltk.download('omw-1.4')
nltk.download('averaged_perceptron_tagger')
from nltk.stem import WordNetLemmatizer
from nltk.corpus import wordnet
# function to convert nltk tag to wordnet tag
lemmatizer = WordNetLemmatizer()
# Finds the part of speech tag
# Convert the detailed POS tag into a shallow information
def nltk_tag_to_wordnet_tag(nltk_tag):
if nltk_tag.startswith('J'):
return wordnet.ADJ
elif nltk_tag.startswith('V'):
return wordnet.VERB
elif nltk_tag.startswith('N'):
return wordnet.NOUN
elif nltk_tag.startswith('R'):
return wordnet.ADV
else:
return None
# lemmatize sentence using pos tag
def lemmatize_sentence(sentence):
# word tokenize -> pos tag (detailed) -> wordnet tag (shallow pos) -> lemmatizer -> root word
#tokenize the sentence and find the POS tag for each token
nltk_tagged = nltk.pos_tag(nltk.word_tokenize(sentence)) # output will be a list of tuples -> [(word,detailed_tag)]
#tuple of (token, wordnet_tag)
wordnet_tagged = map(lambda x: (x[0], nltk_tag_to_wordnet_tag(x[1])), nltk_tagged) # output -> [(word,shallow_tag)]
lemmatized_sentence = []
for word, tag in wordnet_tagged:
if tag is None:
#if there is no available tag, append the token as is
lemmatized_sentence.append(word)
else:
#else use the tag to lemmatize the token
lemmatized_sentence.append(lemmatizer.lemmatize(word, tag))
return " ".join(lemmatized_sentence)
df['Idea_processed'] = df['Idea_processed'].apply(lambda x: lemmatize_sentence(x))
# Importing module
from sklearn.feature_extraction.text import TfidfVectorizer
# Creating matrix of top 2500 tokens
tfidf = TfidfVectorizer(max_features=2500)
# tmp_df = tfidf.fit_transform(df.review_processed)
# feature_names = tfidf.get_feature_names()
# pd.DataFrame(tmp_df.toarray(), columns = feature_names).head()
X = tfidf.fit_transform(df.Idea_processed).toarray()
y = df['deal/no deal'].map({'Deal' : 1, 'No Deal' : 0}).values
featureNames = tfidf.get_feature_names_out()
# # Splitting the dataset into train and test
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.20)
from sklearn.tree import DecisionTreeClassifier
dt = DecisionTreeClassifier()
dt.fit(X_train,y_train)
y_pred = dt.predict(X_test)
user_sentence = user_sentence.replace("[^a-zA-Z0-9]", " ")
user_sentence = ' '.join([x for x in user_sentence.split() if len(x) > 2])
user_sentence = user_sentence.lower()
user_sentence = remove_stopwords(user_sentence)
user_sentence = lemmatize_sentence(user_sentence)
X_test = tfidf.transform([user_sentence]).toarray()
predictdeal= dt.predict(X_test)
a= predictdeal[0]
if a==1:
b="your Idea seems good. you will get a Deal in sharktank 👌"
else:
b="you need to work more on your Idea.you will Not get a Deal in sharktank 👎"
return b
def invest():
df2 = pd.read_excel('SharkTankIndiaS02.xlsx')
df3=df2[["Idea","Brand","Deal","Amit Jain","Namita","Anupam","Vineeta","Aman","Piyush"]].copy()
df3["deal/no deal"]=df2["Deal"].copy()
df3['deal/no deal']=df3['deal/no deal'].apply(lambda x: 'Deal' if x != 'No Deal' else x)
df3["Amit Jain"] = df3["Amit Jain"].replace({'Amit':"Deal", "ABSENT":"No Deal", "NaN":"No Deal"})
df3["Namita"] = df3["Namita"].replace({'Namita':"Deal", "ABSENT":"No Deal", "NaN":"No Deal"})
df3["Anupam"] = df3["Anupam"].replace({'Anupam':"Deal", "ABSENT":"No Deal", "NaN":"No Deal"})
df3["Vineeta"] = df3["Vineeta"].replace({'Vineeta':"Deal", "ABSENT":"No Deal", "NaN":"No Deal"})
df3["Aman"] = df3["Aman"].replace({'Aman':"Deal", "ABSENT":"No Deal", "NaN":"No Deal"})
df3["Piyush"] = df3["Piyush"].replace({'Piyush':"Deal","Peyush":"Deal", "ABSENT":"No Deal", "NaN":"No Deal"})
d = [df3["Amit Jain"].value_counts(), df3["Namita"].value_counts(), df3["Anupam"].value_counts(),df3["Vineeta"].value_counts(), df3["Aman"].value_counts(), df3["Piyush"].value_counts()]
c=pd.DataFrame(d)
c.reset_index(inplace = True)
return c
def interest():
df4 = pd.read_excel('SharkTankIndiaS02.xlsx')
df5=df4[["Idea","Brand","Deal","Amit Jain","Namita","Anupam","Vineeta","Aman","Piyush"]].copy()
df5["Amit Jain"] = df5["Amit Jain"].replace({'Amit':"Deal", "ABSENT":"No Deal", "NaN":"No Deal"})
df5["Namita"] = df5["Namita"].replace({'Namita':"Deal", "ABSENT":"No Deal", "NaN":"No Deal"})
df5["Anupam"] = df5["Anupam"].replace({'Anupam':"Deal", "ABSENT":"No Deal", "NaN":"No Deal"})
df5["Vineeta"] = df5["Vineeta"].replace({'Vineeta':"Deal", "ABSENT":"No Deal", "NaN":"No Deal"})
df5["Aman"] = df5["Aman"].replace({'Aman':"Deal", "ABSENT":"No Deal", "NaN":"No Deal"})
df5["Piyush"] = df5["Piyush"].replace({'Piyush':"Deal","Peyush":"Deal", "ABSENT":"No Deal", "NaN":"No Deal"})
df6=df5[["Idea",option1,option2]]
df7= df6.loc[(df6[option1]=="Deal")&(df6[option2]=="Deal")]
df7["investor"]= df7[option1]
return df7
def data():
df8 = pd.read_excel('SharkTankIndiaS02.xlsx')
df9=df8[["Idea","Deal","Amit Jain","Namita","Anupam","Vineeta","Aman","Piyush"]].copy()
df9["deal/no deal"]=df9["Deal"].copy()
df9['deal/no deal']=df9['deal/no deal'].apply(lambda x: 'Deal' if x != 'No Deal' else x)
df9['deal in binary']=df9['deal/no deal'].apply(lambda x: 1 if x != 'No Deal' else x)
df9["deal in binary"] = df9["deal in binary"].replace(['No Deal'],[0])
# Replacing punctuations with space
df9['Idea_processed'] = df9['Idea'].str.replace("[^a-zA-Z0-9]", " ")
df9['Idea_processed'] = df9['Idea_processed'].astype(str)
df9['Idea_processed'] = df9['Idea_processed'].apply(lambda row: ' '.join([word for word in row.split() if len(word)>2]))
# make entire text lowercase
df9['Idea_processed'] = [row.lower() for row in df9['Idea_processed']]
# Removing Stopwords Begin
import nltk
nltk.download('punkt')
nltk.download('stopwords')
from nltk.corpus import stopwords
from nltk import word_tokenize
stop_words = stopwords.words('english') # extracting all the stop words in english language and storing it in a variable called stop_words -> set
# Making custom list of words to be removed
add_words = ['brand','company']
# Adding to the list of words
stop_words.extend(add_words)
# Function to remove stop words
def remove_stopwords(rev):
# iNPUT : IT WILL TAKE ROW/REVIEW AS AN INPUT
# take the paragraph, break into words, check if the word is a stop word, remove if stop word, combine the words into a para again
review_tokenized = word_tokenize(rev)
rev_new = " ".join([i for i in review_tokenized if i not in stop_words])
return rev_new
# Removing stopwords
df9['Idea_processed'] = [remove_stopwords(r) for r in df9['Idea_processed']]
# Begin Lemmatization
nltk.download('wordnet')
nltk.download('omw-1.4')
nltk.download('averaged_perceptron_tagger')
from nltk.stem import WordNetLemmatizer
from nltk.corpus import wordnet
# function to convert nltk tag to wordnet tag
lemmatizer = WordNetLemmatizer()
# Finds the part of speech tag
# Convert the detailed POS tag into a shallow information
def nltk_tag_to_wordnet_tag(nltk_tag):
if nltk_tag.startswith('J'):
return wordnet.ADJ
elif nltk_tag.startswith('V'):
return wordnet.VERB
elif nltk_tag.startswith('N'):
return wordnet.NOUN
elif nltk_tag.startswith('R'):
return wordnet.ADV
else:
return None
# lemmatize sentence using pos tag
def lemmatize_sentence(sentence):
# word tokenize -> pos tag (detailed) -> wordnet tag (shallow pos) -> lemmatizer -> root word
#tokenize the sentence and find the POS tag for each token
nltk_tagged = nltk.pos_tag(nltk.word_tokenize(sentence)) # output will be a list of tuples -> [(word,detailed_tag)]
#tuple of (token, wordnet_tag)
wordnet_tagged = map(lambda x: (x[0], nltk_tag_to_wordnet_tag(x[1])), nltk_tagged) # output -> [(word,shallow_tag)]
lemmatized_sentence = []
for word, tag in wordnet_tagged:
if tag is None:
#if there is no available tag, append the token as is
lemmatized_sentence.append(word)
else:
#else use the tag to lemmatize the token
lemmatized_sentence.append(lemmatizer.lemmatize(word, tag))
return " ".join(lemmatized_sentence)
df9['Idea_processed'] = df9['Idea_processed'].apply(lambda x: lemmatize_sentence(x))
# Importing module
from sklearn.feature_extraction.text import TfidfVectorizer
# Creating matrix of top 2500 tokens
tfidf = TfidfVectorizer(max_features=2500)
# tmp_df = tfidf.fit_transform(df.review_processed)
# feature_names = tfidf.get_feature_names()
# pd.DataFrame(tmp_df.toarray(), columns = feature_names).head()
X = tfidf.fit_transform(df9.Idea_processed).toarray()
y = df9['deal/no deal'].map({'Deal' : 1, 'No Deal' : 0}).values
featureNames = tfidf.get_feature_names_out()
# # Splitting the dataset into train and test
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.20)
from sklearn.tree import DecisionTreeClassifier
dt = DecisionTreeClassifier()
dt.fit(X_train,y_train)
y_pred = dt.predict(X_test)
from sklearn.metrics import confusion_matrix, accuracy_score
accuracy = accuracy_score(y_test, y_pred)
from sklearn.metrics import roc_auc_score
ra = roc_auc_score(y_test, dt.predict_proba(X_test)[:, 1])
##featureImportance.sort_values(by='Importance')
featureImportance = pd.DataFrame({i : j for i,j in zip(dt.feature_importances_,featureNames)}.items(),columns = ['Importance','word'])
fi=featureImportance.sort_values(by='Importance',ascending=False)
return df9, accuracy, ra, fi
st.set_page_config(layout="wide", initial_sidebar_state='expanded')
# Add back ground image
selected = option_menu(menu_title=None, options=["ML model","Data visualization","Code"], icons=["clipboard-data","award","coin"], orientation="horizontal")
if selected=="ML model":
def add_bg_from_url():
st.markdown(
f"""
<style>
.stApp {{
background-image: url("https://i.ytimg.com/vi/-TO4HaPtVH8/maxresdefault.jpg");
background-attachment: fixed;
background-size: cover
}}
</style>
""",
unsafe_allow_html=True
)
add_bg_from_url()
# GUI.py
cls1,cls2,cls3=st.columns((0.5,3,0.5))
with cls2:
st.title("Will you get :orange[Funding] for your Idea :orange[?]")
cl1,cl2,cl3=st.columns((1,2,1))
with cl2:
# Get input from user for hashtag
user_sentence = st.text_input("Enter the idea:")
if st.button("predict"):
b = shark(user_sentence)
progress_bar = cl2.progress(0)
for perc_completed in range(100):
time.sleep(0.05)
progress_bar.progress(perc_completed+1)
st.button(b)
if selected=="Data visualization":
st.markdown('### Metrics')
col1, col2, col3 = st.columns(3)
col1.metric('Total pitch', '# 163')
col2.metric('Deal', '# 95')
col3.metric('No Deal', '# 68')
with st.sidebar:
selected = option_menu(menu_title=None, options=["About Data","About Investor"], icons=["clipboard-data","coin"], orientation="horizontal")
if selected == "About Investor":
option1= st.selectbox("Select Investor 1",("Amit Jain","Namita","Anupam","Vineeta","Aman","Piyush"))
option2= st.selectbox("Select Investor 2",("Namita","Amit Jain","Anupam","Vineeta","Aman","Piyush"))
if selected == "About Investor":
if st.sidebar.button("show"):
st.markdown('''----''')
c1,c2 = st.columns((6,4))
with c1:
c= invest()
st.markdown('##### Comparing no of deals done by investors')
fig = px.pie(c, values="Deal", names="index", hole=0.75, width=400, height=300)
st.write(fig)
with c2:
df7= interest()
st.markdown('##### Two investors invested in same company')
e=[df7["investor"].value_counts()]
f=pd.DataFrame(e)
f.reset_index(inplace = True)
fig2 = px.bar(f, x="index", y=["Deal"], text_auto=True, width=400, height=300)
st.write(fig2)
st.markdown('''----''')
st.markdown('##### Ideas where both of them invested')
with st.expander("click to read"):
st.dataframe(df7["Idea"])
if selected == "About Data":
if st.sidebar.button("show"):
df9, accuracy, ra, fi=data()
st.markdown('''----''')
st.markdown("##### Data frame head()")
st.dataframe(df9.head())
st.markdown('''----''')
st.markdown("##### ML model score")
colu1,colu2=st.columns(2)
colu1.metric('Accuracy of ML Model', accuracy)
colu2.metric('Auroc Score', ra)
st.markdown('''----''')
st.markdown("##### Feature impotance")
with st.expander("click to read"):
st.dataframe(fi)
if selected=="Code":
def add_bg_from_url():
st.markdown(
f"""
<style>
.stApp {{
background-image: url("https://i.ytimg.com/vi/-TO4HaPtVH8/maxresdefault.jpg");
background-attachment: fixed;
background-size: cover
}}
</style>
""",
unsafe_allow_html=True
)
add_bg_from_url()
colu1,colu2,colu3=st.columns((1,2,1))
with colu2:
with open('C:/Users/DELL/sharktankindia2.pdf', 'rb') as f:
base64_pdf = base64.b64encode(f.read()).decode('utf-8')
st.markdown(f'<embed src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" type="application/pdf">', unsafe_allow_html=True)