Mva Script //free\\ Access
# Step 4: Plot scree plt.figure(figsize=(8,4)) plt.bar(range(1, len(pca.explained_variance_ratio_)+1), pca.explained_variance_ratio_) plt.step(range(1, len(cum_var)+1), cum_var, where='mid', color='red') plt.title('Scree Plot with Cumulative Variance') plt.xlabel('Principal Component') plt.ylabel('Variance Ratio') plt.savefig('scree_plot.png')
# Step 2: Scale features scaler = StandardScaler() data_scaled = scaler.fit_transform(data_imp) mva script
# Step 5: LDA (if labels exist) if labels is not None: lda = LDA(n_components=min(2, len(np.unique(labels))-1)) lda_scores = lda.fit_transform(data_scaled, labels) print("LDA applied. Reduced shape:", lda_scores.shape) # LDA scatter plot plt.figure() for lab in np.unique(labels): subset = lda_scores[labels == lab] plt.scatter(subset[:,0], subset[:,1], label=f'Class {lab}') plt.legend() plt.title('LDA Projection') plt.savefig('lda_plot.png') # Step 4: Plot scree plt