import numpy as np
import pandas as pd
from [Link] import StandardScaler
from [Link] import PCA
# Define the dataset
data = {
'Screen Size': [6.0, 5.5, 7.0],
'Battery Life': [12, 10, 15],
'Camera Resolution': [16, 12, 20],
'Storage Capacity': [128, 64, 256],
'Processing Speed': [2.5, 2.0, 3.0],
'Weight': [150, 120, 180],
'RAM': [4, 3, 8],
'Price': [800, 500, 1200],
'Apps': [30, 20, 50],
'Connectivity': [4, 3, 5]
# Convert the data to a DataFrame
df = [Link](data, index=['Gadget1', 'Gadget2', 'Gadget3'])
# Standardize the data
scaler = StandardScaler()
scaled_data = scaler.fit_transform(df)
# Apply PCA
pca = PCA(n_components=2) # Reduce to 2 dimensions (for example)
pca_result = pca.fit_transform(scaled_data)
# Convert the PCA result to a DataFrame for better readability
pca_df = [Link](pca_result, columns=['PC1', 'PC2'], index=[Link])
# Explained variance by each principal component
explained_variance = pca.explained_variance_ratio_
print("Original Data:\n", df)
print("\nStandardized Data:\n", scaled_data)
print("\nPCA Result (Reduced Dimensions):\n", pca_df)
print("\nExplained Variance by Each Principal Component:", explained_variance)