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

Week 12 Iris Data

Uploaded by

virizionx7
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 views5 pages

Week 12 Iris Data

Uploaded by

virizionx7
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
You are on page 1/ 5

Week 12 Iris Data

'''
https://machinelearningmastery.com/machine-learning-in-python-
step-by-step/
Loads a dataset with assosciated attribute names, then reports on
details
of the dataset including statistics and graphs
'''

# Import necessary libraries


import pandas
from pandas.plotting import scatter_matrix
import matplotlib.pyplot as plt

# Sets up necessary variables to be able to import the data


correctly
file = "iris.csv"
names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width',
'class']

# Load data from the csv file into a pandas dataframe


dataset = pandas.read_csv(file, names=names)

# Display the shape of the dataset


print("The file " + file + " has these dimensions (rows, colums): ")
print(dataset.shape)

# Display the first 20 rows of the dataset


print("\nThe first 20 rows of the dataset:")
print(dataset.head(20))

# Display statistical summary of the dataset


print("\nStatistical summary of the dataset:")
print(dataset.describe())

# Display the class distribution in the dataset


print("\nClass distribution of the dataset:")
print(dataset.groupby('class').size())

# Generate and save box and whisker plots for each attribute
print("\nGenerating box plots")
dataset.plot(kind='box', subplots=True, layout=(2, 2),
sharex=False, sharey=False)
plt.savefig('box.png')
print("Box plots saved as 'box.png'")

# Generate and save histograms for each attribute


print("\nGenerating histograms")
dataset.hist()
plt.savefig('hist.png')
print("Histograms saved as 'hist.png'")
# Generate and save a scatter plot matrix
print("\nGenerating scatter plot matrix")
scatter_matrix(dataset)
plt.savefig('matrix.png')
print("Scatter plot matrix saved as 'matrix.png'")

print("\nAll plots have been saved in the current directory")

You might also like