0% found this document useful (0 votes)
3 views2 pages

3rd Program

The document outlines a program to implement Principal Component Analysis (PCA) on the Iris dataset, reducing its dimensionality from 4 features to 2. It includes loading the dataset, performing PCA, creating a DataFrame for the reduced data, and plotting the results. The visualization distinguishes different species of Iris using colors in a scatter plot.

Uploaded by

Kartik Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

3rd Program

The document outlines a program to implement Principal Component Analysis (PCA) on the Iris dataset, reducing its dimensionality from 4 features to 2. It includes loading the dataset, performing PCA, creating a DataFrame for the reduced data, and plotting the results. The visualization distinguishes different species of Iris using colors in a scatter plot.

Uploaded by

Kartik Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Develop a program to implement Principal Component Analysis (PCA) for reducing the

dimensionality of the Iris dataset from 4 features to 2.

import numpy as np

import pandas as pd

from [Link] import PCA

import [Link] as plt

# Load the Iris dataset from local system

iris_df = pd.read_csv("absolute_path_of_iris.csv")

data = iris_df.iloc[:, :-1].values

labels = iris_df.iloc[:, -1].values

label_names = [Link](labels)

# Perform PCA to reduce dimensionality to 2

pca = PCA(n_components=2)

data_reduced = pca.fit_transform(data)

# Create a DataFrame for the reduced data

reduced_df = [Link](data_reduced, columns=['Principal Component 1', 'Principal


Component 2'])

reduced_df['Label'] = labels

# Plot the reduced data

[Link](figsize=(8, 6))

colors = ['r', 'g', 'b']

for i, label in enumerate(label_names):

[Link](
reduced_df[reduced_df['Label'] == label]['Principal Component 1'],

reduced_df[reduced_df['Label'] == label]['Principal Component 2'],

label=label,

color=colors[i]

[Link]('PCA on Iris Dataset')

[Link]('Principal Component 1')

[Link]('Principal Component 2')

[Link]()

[Link]()

[Link]()

You might also like