Question: needing help with index error: 9 . Visualize the first five sentences embedding for each tweet using PCA import spacy # Load the large model
needing help with index error:
Visualize the first five sentences embedding for each tweet using PCA
import spacy
# Load the large model
nlp spacy.loadencoreweblg
tweets.index rangelentweets
#databc
dataac
# Generate only the first sentencedoc embeddings
topn
for idx, row in tweets.iterrows:
if idx topn:
dataacappendrowtweet nlprowtweetvector, rowtarget
else:
break
#Store the results in the dfs
dfac pdDataFramedataac columnsreviewac "vector", "target"
pprintdfac
from sklearn.decomposition import PCA
dfacindex rangelendfac
Xac nparraylistdfacvector
# Extract principal componets using PCA
pca PCAncomponents
pcaacd pca.fittransformXac
reviewac dfacreviewac
fig, ax pltsubplots figsize
fig.suptitleVisualize Sentence Vectors Using PCA', fontsize
# Color the sentence embeddings based on the airline sentiment
colors :'green', :'red'
axscatterpcaacd:pcaacd: s c dfactargetmapcolors
cmap "coolwarm", edgecolor "None", alpha
# Label the points using the texts
for idx, txt in enumeratereviewac:
axannotatetxtpcaacdidxpcaacdidx #IndexError: index is out of bounds for axis with size
axsettitleScatter Plot for Cleaned Texts', fontsize
pltshow
example of df:
example of df:
reviewac
cant sleep gahh. better try again atleast. ni
@zincous It's still in the works... I promise
@realAdamBeyer how can I get drumcode products...
@CupcakeSmile Thanks i appreciate that
@MeesLovesYou Grounded from the computer...
vector target
dataset head:
target tweet lentarget countword
cant sleep gahh. better try again atleast. ni
@zincous It's still in the works... I promise
@realAdamBeyer how can I get drumcode products...
@CupcakeSmile Thanks i appreciate that
@MeesLovesYou Grounded from the computer...
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
