-1

I am trying to visualize the 3 features of my dataframe using MDS to scale them in 2 dimensions.

So, I performed MDS in 2 dimensions to plot the new data, giving each point a different color according to the target variable. my target variable is 'Type'

In: df

 Sales    hours     month    Type
  243      13        5        A
  111      4         3        B
  250      7         7        C
  101      12        1        A
X = df
X = pd.get_dummies(X)
scaler = MinMaxScaler()
X_scaled = scaler.fit_transform(X)

# Apply the MDS
mds = MDS(2,random_state=0)
X_2d = mds.fit_transform(X_scaled)

# Plot the new dataset.
colors = ['red','green','blue']
plt.rcParams['figure.figsize'] = [7, 7]
plt.rc('font', size=14)

for i in np.unique(df.Type):
  subset = X_2d[df.Type == i]
  
  x = [row[0] for row in subset]
  y = [row[1] for row in subset]

plt.scatter(x,y,c=colors[i],label= df.target_names[i])
plt.legend()
plt.show()

When I applied the MDS, it works well and the new dataset is generated.

But my problem is in the plotting.

TypeError: list indices must be integers or slices, not str

----> plt.scatter(x,y,c=colors[i],label=all_outliers_type.target_names[i])

MohammedE
  • 99
  • 2
  • 10

1 Answers1

0

Seems like your indentation is off: you're calling colors[i] outside of your for loop, and i seems to be one of "A", "B", "C".

Be Chiller Too
  • 2,502
  • 2
  • 16
  • 42