






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







WGU D600 Task 3: Principal Component Analysis (PCA) & Regression Complete Report, Python Modeling & Evaluation Course: D600 – Statistical Data Mining Task: Task 3 – Principal Component Analysis (PCA) & Regression Tool: Python (pandas, scikit-learn, statsmodels, matplotlib) Dataset: Home Price Dataset (illustrative; replace with your assigned dataset) A. GitHub Repository A subgroup and project were created in GitHub for Task 3. The project was cloned into the IDE, and commits were made after the completion of each rubric-aligned section. Each commit included a descriptive message and timestamp to ensure proper version tracking. The GitHub repository URL was submitted in the “Comments to Evaluator” section as instructed, and the full branch history was exported and included in the final submission. B. Research Question and Goal B1. Proposal of Question Research Question: How do structural characteristics (square footage, number of bedrooms, backyard space, age of home, renovation quality, previous sale price)
and neighborhood factors (crime rate, school rating, distance to city center, employment rate, property tax rate, local amenities, transportation access) influence housing prices in the dataset? This question reflects a real-world organizational concern relevant to property valuation and real estate analytics. The problem is suited for linear regression modeling because it examines the relationship between a continuous dependent variable (home price) and multiple quantitative explanatory variables. B2. Defined Goal The goal of the analysis was to build a predictive model of home prices using principal component analysis (PCA) to reduce multicollinearity, followed by a linear regression model using the retained principal components as predictors. This approach resolves redundancy among correlated housing variables while preserving the majority of the dataset’s variance. C. PCA Justification and Assumptions C1. Why PCA Was Used Principal component analysis was used to transform a set of correlated continuous variables into a smaller number of uncorrelated components. The PCA reduced redundancy, resolved multicollinearity, and improved the reliability of the subsequent linear regression model. The expected outcome was a reduced dataset where the retained components captured the majority of total variance, enabling effective and interpretable model training. C2. Fundamental Assumption of PCA One fundamental assumption of PCA is that the principal components are uncorrelated linear combinations of the original variables. This ensures that each component captures a unique dimension of the dataset’s variance and contributes independently to the regression model. In this analysis, the assumption held: the PCA transformed the original correlated variables into orthogonal (uncorrelated) components. D. Variable Identification and Standardization
To determine how many principal components to retain, a Kaiser test was applied: retain components with eigenvalues > 1. A scree plot was also generated to visually inspect the elbow. In the illustrative dataset, the first 6 components had eigenvalues greater than 1. These 6 components collectively explained a substantial proportion of the total variance (typically >70% in housing datasets). Therefore, PC1 through PC6 were retained for the regression model. Note: The exact number of components retained depends on your specific dataset. The principle is: retain components with eigenvalue > 1 and/or those before the elbow in the scree plot, while ensuring a meaningful cumulative variance explained (e.g., ≥70%). F. Regression Modeling Using Principal Components F1. Critical Rule: Use Principal Components, Not Original Features A major point of confusion has been resolved by recent student guidance and instructor confirmation: you must use the principal components (PCs) in your regression model, not the original features. The PCA transforms the original predictors into new orthogonal variables (PC1, PC2, …), and these PCs become the predictors in the regression. F2. Model Specification The regression model was specified as: HomePrice = 𝛽 0 + 𝛽 1 (PC1) + 𝛽 2 (PC2) + 𝛽 3 (PC3) + 𝛽 4 (PC4) + 𝛽 5 (PC5)
# Note: target is NOT standardized y = df[target] _# ------------------------------------------------------------
pca = PCA() pca.fit(X_scaled_df) # Explained variance and eigenvalues explained_var = pca.explained_variance_ratio_ eigenvalues = pca.explained_variance_ # Scree plot plt.figure(figsize=(8, 5)) plt.plot(range(1, len(eigenvalues) + 1), eigenvalues, 'o-', linewidth=2) plt.axhline(y=1, color='r', linestyle='--', label='Kaiser criterion (eigenvalue = 1)') plt.xlabel('Principal Component') plt.ylabel('Eigenvalue') plt.title('Scree Plot') plt.legend() plt.grid(True)
plt.show() # Kaiser criterion: retain components with eigenvalue > 1 n_components = np.sum(eigenvalues > 1) print(f"Components retained (eigenvalue > 1): {n_components}") print(f"Cumulative variance explained: {explained_var[:n_components].sum():.2%}") _# ------------------------------------------------------------
pca_retained = PCA(n_components=n_components) X_pca = pca_retained.fit_transform(X_scaled_df) X_pca_df = pd.DataFrame( X_pca, columns=[f'PC{i+1}' for i in range(n_components)] ) _# ------------------------------------------------------------
X_reg = sm.add_constant(X_pca_df) model = sm.OLS(y, X_reg).fit()
pca_retained.components_.T, columns=[f'PC{i+1}' for i in range(n_components)], index=continuous_vars ) print("\nPCA Loadings:") print(loadings.round(3)) _# ------------------------------------------------------------
vif_data = pd.DataFrame() vif_data["feature"] = X_pca_df.columns vif_data["VIF"] = [variance_inflation_factor(X_pca_df.values, i) for i in range(X_pca_df.shape[1])] print("\nVIF for Principal Components:") print(vif_data) H. Summary of Findings