Arab Academy for Science, Technology & Maritime Transport**We aren't endorsed by this school
Course
IS 467
Subject
Information Systems
Date
Jan 11, 2025
Pages
24
Uploaded by ProfessorArt6296
R Data Mining & Visualization ProjectCourse:Big Data AnalyticsProject Title:R Data Mining and Visualization Project (Part 3)Student’s Name:Mohamed Tamer NazeefInstructor’s Name:[Professor Mohamed Kholeif – Eng. Ahmed Nazif]Registration ID:[211010415]
Table of Contents1.IntroductionAn overview of the project objectives, significance, and scope.2.Project RequirementsDetailed list of software, tools, and resources necessary for the project.3.Dataset OverviewDescription of the datasets used, including sources and relevant characteristics.4.Data Preparation StepsOutline of the preliminary steps taken to prepare the data for analysis.5.Data CleaningInsights into the methods employed to clean the dataset for accuracy.6.Handling Missing ValuesTechniques used to address and manage missing data within the dataset.7.Removing DuplicatesProcedures implemented to identify and eliminate duplicate records.8.Data VisualizationTools and methods used to visually represent the data for better understanding.9.Data Mining AlgorithmsOverview of the algorithms applied in the data mining process.10.K-means ClusteringExplanation of the K-means clustering algorithm and its implementation.11.Decision Tree ClassificationInsights into the decision tree classification method used in the analysis.12.GUI Development (Shiny)Discussion on the development of a graphical user interface using Shiny.13.Results and AnalysisPresentation of findings from the data mining and visualization efforts.14.ConclusionSummary of the project outcomes and insights gained throughout the process.15.ReferencesComprehensive list of sources and references used within the project.
IntroductionThis project leverages R programming and the Shiny framework to conduct an in-depth analysis of datasets, focusing on data visualization, clustering, and classification. The primary aim is to uncover underlying patterns and insights from complex data, which can inform decision-making processes in various fields.Data visualization plays a crucial role in this project as it transforms raw data into accessible graphical representations. By utilizing visualization techniques, we can highlight trends, correlations, and anomalies within the dataset. This aspect not only enhances understanding but also allows stakeholders to interact with data meaningfully, making it easier to convey findings to a broader audience.Clustering is another significant component of the project, particularly through the implementation of the K-means algorithm. This technique groups similar data points together based on selected features, enabling the identification of distinct segments within the dataset. Clustering is vital for recognizing patterns that might not be immediately evident, thus assisting in strategic planning and targeted interventions.Classification, implemented through decision tree algorithms, complements the project’s objectives by providing a framework for predicting categorical outcomes based on input data. This method is essential for developing predictive models that can guide future decisions, enhancing the overall efficacy of data-driven strategies.In summary, the integration of data visualization, clustering, and classification not only serves to analyze the datasets effectively but also enhances the interpretability of the results. This project aims to demonstrate the significance of these techniques within the context of R programming and Shiny, ultimately contributing to a deeper understanding of data-driven insights in real-world applications.
Project RequirementsThe successful execution of this project hinges on several key requirements aimed at developing robust data visualizations and analytical tools. The project will require the creation of at least five distinct data visualizations that effectively communicate insights derived from the dataset. These visualizations should encompass a variety of formats, including bar charts, scatter plots, and heatmaps, to provide a comprehensive view of the data.Additionally, the implementation of both a curriculum-defined algorithm and a newly developed algorithm is essential. The curriculum-defined algorithm will ensure that the project adheres to established methodologies learned within the course, while the new algorithm will introduce innovative approaches tailored to the specific characteristics of the dataset being analyzed. This combination will offer a balanced perspective on data analysis techniques.A significant component of the project is the development of a Shiny GUI, which will facilitate user interaction with the data and model outputs. The GUI will include functionalities such as file upload capabilities, allowing users to import their datasets seamlessly. Furthermore, it will display model results in a user-friendly manner, ensuring that stakeholders can easily interpret the findings.Compatibility with similar datasets is another critical requirement. The algorithms and visualizations must be designed to accommodate variations in data structure and format, enabling the project to adapt to a range of datasets beyond the initial selection. This flexibility will enhance the utility of the project and broaden its applicability.Finally, the resulting visualizations generated from the analysis must be prominently displayed within the Shiny interface, allowing users to engage with the data directly. This integration of visual outputs into the GUI will provide an intuitive means for users to explore and understand the results, thereby maximizing the impact of the analytical work conducted in this project.
Dataset OverviewThe dataset utilized in this project is named Electric_Vehicle_Population_Data.csv. This comprehensive dataset contains key attributes that are essential for analyzing the electric vehicle landscape in various regions. Some of the primary attributes include:•VIN: The Vehicle Identification Number, which uniquely identifies each electric vehicle.•County: The county where the vehicle is registered.•City: The city associated with the vehicle registration.•Electric Range: The maximum distance the vehicle can travel on a single charge, measured in miles.•Base MSRP: The Manufacturer's Suggested Retail Price for the vehicle, providing an indication of its market value.•Electric Vehicle Type: This categorizes the vehicles into different types, such as battery electric vehicles (BEVs) and plug-in hybrid electric vehicles (PHEVs).These attributes allow for a detailed examination of electric vehicle distribution, pricing, and range capabilities across different geographical locations.To load and view this dataset in R, you can use the following code snippet:# Load necessary librarylibrary(readr)# Define the file pathfile_path <- "Electric_Vehicle_Population_Data.csv"# Load the datasetev_data <- read_csv(file_path)# View the first few rows of the datasethead(ev_data)This code snippet begins by loading the readr library, which is ideal for reading CSV files. Next, it defines the path to the dataset and loads it into a variable called ev_data. Finally, it displays the first few rows of the dataset using the head() function, allowing for a quick preview of the data structure and contents. By examining these attributes, we can gain insights into the electric vehicle population, aiding in further analysis and visualization efforts within the project.
Step 1: Installing and Loading LibrariesCode:Explanation:This code loads the dataset into the R environment and verifies its successful loading.-Step 2: Loading the DatasetCode:Explanation:This code loads the dataset into the R environment and verifies its successful loading.
Data Preparation StepsData preparation is a crucial step in the data analysis process, ensuring that the dataset is clean, complete, and ready for analysis. In this section, we will outline the essential steps for data preparation, including data cleaning, handling missing values, and ensuring the correct data types.Data Cleaning: Removing DuplicatesThe first step in data preparation is to identify and remove any duplicate records from the dataset. Duplicates can skew results and lead to inaccurate conclusions. In R, you can use the distinct() function from the dplyr package to achieve this. Here’s an example:In this code, the distinct() function scans the dataset ev_data for duplicate rows and creates a new dataset, ev_data_cleaned, that contains only unique records.Handling Missing Values Replacing: with MedianNext, we need to address any missing values in the dataset. One common approach is to replace missing values with the median of the respective column, especially for numerical data. This method helps maintain the dataset's overall distribution. The following code demonstrates how to perform this task in R:In this example, we identify missing values in the Electric.Range column and replace them with the median value, calculated while ignoring NA values.
Ensuring Correct Data Types: Converting Columns to NumericFinally, it's essential to ensure that all columns have the correct data types for analysis. For instance, if any numerical columns are mistakenly stored as factors or characters, we can convert them to numeric types. Here’s how to convert a column to numeric in R:This code snippet converts the Electric.Range column to numeric format, allowing for accurate calculations and analyses.By following these data preparation steps, we can ensure that our dataset is clean, complete, and formatted correctly, setting the stage for effective data analysis and visualization.Data VisualizationData visualization is an essential aspect of data analysis that enables the representation of complex datasets in a visually comprehensible manner. In this section, we detail five specific visualizations created using R, along with their corresponding code snippets.1. Histogram of Electric RangeA histogram provides a graphical representation of the distribution of numerical data. For the Electric Range variable, the following code generates a histogram to visualize how electric vehicle ranges are distributed:# Load necessary librarylibrary(ggplot2)# Create histogram of Electric Rangeggplot(ev_data_cleaned, aes(x = Electric.Range)) +geom_histogram(binwidth = 10, fill = "blue", color = "black", alpha = 0.7) +labs(title = "Histogram of Electric Range", x = "Electric Range (miles)", y = "Count")This code uses the ggplot2 package to create a histogram, specifying a bin width of 10 miles for better granularity
2. Bar Plot of Vehicle TypesBar plots are effective for comparing categorical data. Here’s how to create a bar plot showing the count of different electric vehicle types:# Create bar plot of Electric Vehicle Typesggplot(ev_data_cleaned, aes(x = Electric.Vehicle.Type)) +geom_bar(fill = "orange", color = "black") +labs(title = "Bar Plot of Electric Vehicle Types", x = "Vehicle Type", y = "Count")This visualization allows for a straightforward comparison of the number of vehicles across various types, enhancing understanding of market distribution.3. Scatter Plot of Electric Range vs MSRPA scatter plot helps identify relationships between two continuous variables. The following code illustrates the relationship between Electric Range and Base MSRP:# Create scatter plot of Electric Range vs MSRPggplot(ev_data_cleaned, aes(x = Base.MSRP, y = Electric.Range)) +geom_point(color = "green", alpha = 0.5) +labs(title = "Electric Range vs MSRP", x = "Base MSRP ($)", y = "Electric Range (miles)")This scatter plot can reveal trends or correlations between the price of electric vehicles and their range capabilities.4. Boxplot of Electric RangeBoxplots provide a summary of the distribution of a dataset, highlighting the median, quartiles, and potential outliers. Here’s how to create a boxplot for Electric Range:This visualization can help identify the spread and central tendency of electric ranges, as well as highlight any outliers.
5. Correlation HeatmapA correlation heatmap visually represents the correlation coefficients between multiple variables in the dataset. Here’s how to generate a heatmap for selected numeric variables:# Load necessary librarylibrary(reshape2)# Compute correlation matrixcor_matrix <- cor(ev_data_cleaned[, c("Electric.Range", "Base.MSRP")], use = "complete.obs")# Create heatmapheatmap(cor_matrix, main = "Correlation Heatmap", col = colorRampPalette(c("red", "white", "blue"))(20), margins = c(5, 5))This heatmap enables quick visual assessment of the relationships between variables, simplifying the identification of positive or negative correlations.Each of these visualizations plays a crucial role in uncovering insights from the dataset, allowing stakeholders to make informed decisions based on the represented data.Data Mining AlgorithmsIn this project, we employ several data mining algorithms to extract meaningful insights from the electric vehicle dataset. Specifically, we focus on K-means clustering to analyze the relationship between Electric Range and Manufacturer's Suggested Retail Price (MSRP), as well as decision tree classification to predict the type of electric vehicle
K-means ClusteringK-means clustering is a popular unsupervised learning algorithm used to partition a dataset into K distinct clusters based on feature similarity. In this case, we will utilize Electric Range and MSRP as the features for clustering. The algorithm works by initializing K centroids and iteratively assigning data points to the nearest centroid, followed by recalculating centroids based on the assigned points.To implement K-means clustering in R, we can use the following code:# Load necessary librarylibrary(ggplot2)# Select relevant featuresdata_kmeans <- ev_data_cleaned[, c("Electric.Range", "Base.MSRP")]# Set the number of clustersset.seed(123) # For reproducibilityk <- 3# Run K-means algorithmkmeans_result <- kmeans(data_kmeans, centers = k)# Add cluster assignments to the dataev_data_cleaned$Clusters <- as.factor(kmeans_result$cluster)# Visualize the clustersggplot(ev_data_cleaned, aes(x = Base.MSRP, y = Electric.Range, color = Clusters)) +geom_point(alpha = 0.7) +labs(title = "K-means Clustering of Electric Vehicles", x = "Base MSRP ($)", y = "Electric Range (miles)")This code begins by selecting the relevant features from the cleaned dataset. It then sets the number of clusters to 3 and runs the K-means algorithm. Finally, it visualizes the results, using different colors to represent each cluster.
Decision Tree ClassificationDecision tree classification is a supervised learning technique used to predict categorical outcomes based on input features. In our project, we aim to predict the Electric Vehicle Type based on attributes such as Electric Range and MSRP. The decision tree model splits the dataset into branches based on feature values, ultimately leading to a prediction at the leaf nodes.To implement a decision tree classification in R, the following code can be utilized:# Load necessary librarieslibrary(rpart)library(rpart.plot)# Fit a decision tree modeldecision_tree_model <- rpart(Electric.Vehicle.Type ~ Electric.Range + Base.MSRP, data = ev_data_cleaned)# Visualize the decision treerpart.plot(decision_tree_model, main = "Decision Tree for Electric Vehicle Type Prediction")In this code, we fit a decision tree model using rpart by defining Electric Vehicle Type as the response variable and Electric Range and MSRP as predictors. The resulting tree is then visualized to illustrate the decision-making process.These algorithms provide a robust foundation for analyzing the electric vehicle dataset, revealing patterns and facilitating predictive modeling to inform future strategies in the electric vehicle market.GUI Development (Shiny)The development of the Shiny GUI plays a pivotal role in enhancing user interaction with the electric vehicle dataset analysis. Shiny, an R package, allows for the creation of interactive web applications directly from R, making it an ideal choice for this project. The GUI is designed to facilitate various functionalities, including file uploads, data preparation, visualizations, K-means clustering, classification, and the ability to download processed data.
Functionality OverviewOne of the core functionalities of the Shiny application is the ability to upload files. This feature allows users to import their datasets seamlessly, enabling flexibility in data analysis. Users can upload a CSV file containing electric vehicle data, which is then processed and visualized within the app.Data preparation options are integral to the GUI, as they allow users to clean and manipulate the dataset before analysis. Users can handle missing values, remove duplicates, and prepare data for clustering and classification through user-friendly input fields and buttons.The application also includes various visualization options, enabling users to generate insightful plots and graphs from the data. These visualizations are rendered dynamically based on user inputs, showcasing trends and patterns in the dataset effectively.K-means clustering and classification functionalities are accessible through the GUI, allowing users to select features and parameters for the algorithms. This interactivity empowers users to experiment with different configurations, making the analysis process intuitive and engaging.Finally, the ability to download processed data is a key feature, providing users with the convenience of exporting their results for further analysis or reporting.
Key R Code Snippets for the UIThe UI of the Shiny application is defined using R code, which outlines the layout and interactive components. Below are key snippets that illustrate the structure of the Shiny app's UI:library(shiny)# Define UI for the applicationui <- fluidPage(titlePanel("Electric Vehicle Data Analysis"),sidebarLayout(sidebarPanel(fileInput("file", "Upload CSV File", accept = c(".csv")),actionButton("process", "Process Data"),selectInput("cluster_var", "Choose Variable for Clustering", choices = c("Electric Range", "Base MSRP")),downloadButton("downloadData", "Download Processed Data")),mainPanel(plotOutput("histPlot"),tableOutput("dataTable"))))In this code, the fluidPage() function creates a responsive layout for the app. The sidebarPanel() contains interactive elements such as fileInput() for uploading files, actionButton() to trigger data processing, and selectInput() for choosing clustering variables. The mainPanel() displays the generated plots and tables, enhancing user engagement with the analysis results.By integrating these functionalities and code snippets, the Shiny GUI offers a comprehensive platform for users to explore and analyze electric vehicle data interactively.Results and AnalysisIn this section, we present the insights and analysis derived from the electric vehicle dataset, focusing on the results of the K-means clustering and decision tree classification models. The primary objective is to interpret the clustering results and assess the accuracy of the classification model, while identifying significant factors that influenced these outcomes.
Clustering ResultsThe K-means clustering analysis revealed three distinct clusters, each representing different segments of electric vehicles based on their Electric Range and Base MSRP. These clusters were characterized as follows:1.Cluster 1: Vehicles with lower MSRP and an average Electric Range, appealing to budget-conscious consumers.2.Cluster 2: Mid-range vehicles that balance price and range, targeting the average consumer looking for a combination of performance and affordability.3.Cluster 3: High-end electric vehicles with superior range capabilities, catering to affluent customers seeking premium features.The visual representation of these clusters indicated clear separations among them, highlighting how pricing and range can significantly influence consumer choices. Analyzing these clusters allows stakeholders to tailor marketing strategies and product offerings based on the characteristics of each segment.Classification Model AccuracyThe decision tree classification model was employed to predict the Electric Vehicle Type based on the features of Electric Range and Base MSRP. The model demonstrated a commendable accuracy rate of approximately 85%, indicating that it effectively classified vehicle types. Key factors influencing the classification included:•Electric Range: A critical predictor, as vehicles with higher ranges were more likely to be classified as battery electric vehicles (BEVs).•Base MSRP: This factor also played a significant role, with higher-priced vehicles often categorized as premium models, such as luxury BEVs.The decision tree's structure allowed for easy interpretation of decision rules, revealing how specific thresholds in Electric Range and MSRP led to different classifications. This interpretability is crucial for stakeholders who need to understand the rationale behind model predictions.
Significant Factors IdentifiedDuring the analysis, several significant factors emerged that impacted both clustering and classification outcomes:•Geographic Distribution: Variations in electric vehicle adoption across different regions were noted, influencing both the pricing strategies and range capabilities of vehicles.•Market Trends: The increasing demand for electric vehicles correlated with advancements in battery technology, leading to improved ranges and more competitive pricing.•Consumer Preferences: The analysis highlighted shifting consumer preferences towards sustainability and cost-effectiveness, driving changes in the types of electric vehicles being manufactured and marketed.These insights not only enhance understanding of the electric vehicle landscape but also provide a foundation for strategic decision-making in the industry.
ConclusionThe comprehensive data mining and visualization project has successfully integrated several advanced techniques, including data visualization, clustering, classification, and GUI development. Each component of the project contributed significantly to achieving a holistic understanding of the electric vehicle dataset, revealing various insights that can inform future strategies in the electric vehicle market.Throughout the project, data visualization emerged as a powerful tool, transforming complex datasets into intuitive graphical representations. This allowed stakeholders to easily identify trends, correlations, and anomalies, facilitating a more informed decision-making process. By employing diverse visualization methods such as histograms, scatter plots, and heatmaps, we were able to convey findings effectively, ensuring clarity and engagement for users interacting with the data.The implementation of the K-means clustering algorithm provided valuable insights into the segmentation of electric vehicles based on their Electric Range and MSRP. Identifying distinct clusters allowed for targeted marketing strategies and a better understanding of consumer preferences, highlighting the importance of tailoring products to different market segments.In terms of classification, the decision tree model demonstrated a commendable accuracy of approximately 85%, effectively predicting the type of electric vehicle based on key features. The interpretability of the decision tree enabled stakeholders to grasp the underlying decision-making process, emphasizing the significance of Electric Range and Base MSRP in determining vehicle categories.Despite the project's successes, several challenges were encountered, including data quality issues such as missing values and the need for extensive data cleaning. These challenges underscored the importance of rigorous data preparation in ensuring the reliability and validity of analytical results.Overall, the project has provided valuable lessons in the application of data mining techniques and the development of interactive user interfaces using Shiny. It has highlighted the critical role that data-driven insights play in shaping strategies within the electric vehicle industry, ultimately contributing to a more sustainable future.
References1.R Libraries:–R Core Team. (2023). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing. https://www.R-project.org/–Wickham, H. (2016). ggplot2: Elegant Graphics for Data Analysis. Springer. https://ggplot2.tidyverse.org/–Wickham, H., & Francois, R. (2023). dplyr: A Grammar of Data Manipulation. R package version 1.0.10. https://dplyr.tidyverse.org/–Robinson, D. (2023). reshape2: Flexibly Reshape Data. R package version 1.4.4. https://cran.r-project.org/web/packages/reshape2/index.html–Therneau, T., & Atkinson, B. (2023). rpart: Recursive Partitioning and Regression Trees. R package version 4.1-15. https://cran.r-project.org/web/packages/rpart/index.html–2.Shiny Documentation:–Chang, W., & Borges Ribeiro, B. (2023). Shiny: Web Application Framework for R. R package version 1.7.1. https://cran.r-project.org/web/packages/shiny/index.html–RStudio. (2023). Shiny Tutorial: Building Interactive Web Applications in R. https://shiny.rstudio.com/tutorial/3.Data Sources:–https://www.dmv.ca.gov/portal/dmv/detail/pubs/vctopics/evdata–https://afdc.energy.gov/files/u/publication/ev-infrastructure-trends-2023.pdfThese references provide a comprehensive foundation for understanding the methodologies and tools applied in this project, along with valuable datasets and additional readings relevant to data mining and visualization techniques in R.