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

Machine Learning with Python Guide

The document discusses machine learning using the Iris dataset in Python. It explains that datasets need credible data sources and sufficient size. The Iris dataset is recommended for beginners as it has numeric attributes, is a small classification problem with 4 attributes and 150 rows, and requires no special preprocessing. The document shows how to load the Iris data, view its dimensions and statistics, and breakdown classes. Finally, it demonstrates univariate and multivariate data visualization techniques like box plots, histograms, and scatter plots to better understand the Iris dataset attributes and relationships.

Uploaded by

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

Machine Learning with Python Guide

The document discusses machine learning using the Iris dataset in Python. It explains that datasets need credible data sources and sufficient size. The Iris dataset is recommended for beginners as it has numeric attributes, is a small classification problem with 4 attributes and 150 rows, and requires no special preprocessing. The document shows how to load the Iris data, view its dimensions and statistics, and breakdown classes. Finally, it demonstrates univariate and multivariate data visualization techniques like box plots, histograms, and scatter plots to better understand the Iris dataset attributes and relationships.

Uploaded by

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

Faculty of Computer Science

University of Sunderland

Machine Learning in Python


In order to start the machine learning process, you need to possess a set of data to be used for training
the algorithm. It's very important to ensure that the source of data is credible, otherwise you would
receive incorrect results, even if the algorithm itself is working correctly (following the garbage in,
garbage out principle).

The second important thing is the size of the dataset. There is no straightforward answer for how large
it should be. The answer may depend on many factors, for example:

• the type of problem you're looking to solve,


• the number of features in the data,
• the type of algorithm used.

The best small project to start with on a new tool is the classification of iris flowers (e.g. the iris
dataset). This is a good project because it is so well understood and it’s used in tons of examples.

• Attributes are numeric so you have to figure out how to load and handle data.
• It is a classification problem, allowing you to practice with perhaps an easier type of
supervised learning algorithm.
• It is a multi-class classification problem (multi-nominal) that may require some specialized
handling.
• It only has 4 attributes and 150 rows, meaning it is small and easily fits into memory (and a
screen or A4 page).
• All of the numeric attributes are in the same units and the same scale, not requiring any
special scaling or transforms to get started.

Loading libraries and importing the dataset, enter and run:

Now it is time to take a look at the data. We are going to take a look at the data a few different
ways:

1. Dimensions of the dataset.


2. Peek at the data itself.
3. Statistical summary of all attributes.
4. Breakdown of the data by the class variable.
Faculty of Computer Science
University of Sunderland

We can get a quick look at the dimensions of the data with the shape property:

We can see the whole data set with the following code:

Note: the 20 in brackets will show us the first 20 rows of the dataset, you can edit this to see more or
less data.

We can see a statistical summary of our dataset by using the describe function. This will give us a
summary of each attribute including the count, mean, the min and max values as well as some
percentiles.

Let’s now take a look at the number of instances (rows) that belong to each class. We can view this as
an absolute count, it is known as the class distribution.

You should now have a basic idea about the data. We need to extend that with some visualizations
Faculty of Computer Science
University of Sunderland

Data Visualisation

Viewing your data in python relies on matplotlib libraries, before we look at the Iris dataset, here are
some code examples that will help you understand how data is presented.

Enter and run the code below:

You should get the following output:

Next we can add some markers:

You should get the following output:


Faculty of Computer Science
University of Sunderland

Now let’s go back to our Iris dataset, we ae going to look at different types of plots.

1. Univariate plots to better understand each attribute.


2. Multivariate plots to better understand the relationships between attributes.

We start with some univariate plots, that is, plots of each individual variable. Given that the input
variables are numeric, we can create box and whisker plots of each. Enter and run the following code
after you have imported the dataset:

This should give you a much clearer idea of the distribution of the input attributes.

We can also create a histogram of each input variable to get an idea of the distribution:

It looks like perhaps two of the input variables have a Gaussian distribution. This is useful to note as
we can use algorithms that can exploit this assumption.

Multivariate plots allow us to see the interactions between the variables in our dataset. If we look at
scatterplots of pairs of attributes, it can help us spot structured relationships between those variables.
Faculty of Computer Science
University of Sunderland

Given that we are going to be using matplotlib to display 3d data and graphs, we need to switch to a
different coding environment. Close everything down and relaunch Anaconda, but this time select
Spyder instead of Jupyter.

Type in and run the following code:

Common questions

Powered by AI

Univariate plots play a crucial role in understanding individual dataset attributes by visualizing data distribution. These plots, such as box and whisker plots or histograms, allow for the identification of outliers, trends, and the underlying distribution of data, such as normality. This can be beneficial in data preparation for machine learning as it informs decisions on data cleaning, normalization, and the choice of algorithm, especially those that assume a specific data distribution. Identifying attributes with Gaussian distributions, for example, can allow the use of algorithms that best exploit these characteristics .

Challenges from using small datasets in machine learning include overfitting, limited generalizability, and inadequate representation of the problem space. Overfitting occurs as models learn from noise rather than signal, reducing their performance on unseen data. These challenges can be addressed by applying techniques like cross-validation to mitigate overfitting, augmenting the dataset with synthetic data if possible, or using regularization methods to enhance generalizability. Moreover, choosing simpler models that require fewer data points can also help address these issues effectively .

The garbage in, garbage out principle in machine learning means that the quality of the input data directly affects the quality of the output results. If the data source is not credible or is error-prone, the algorithm's results will likely be incorrect, regardless of the algorithm's accuracy. To mitigate its effects, ensuring data credibility and accuracy is essential, which involves thorough data pre-processing, validation checks, and using reliable data sources. Additionally, exploratory data analysis can help identify and correct inconsistencies or errors in the dataset before training .

The Iris dataset is considered a suitable starting project for beginners in machine learning because it is well-understood and commonly used in educational examples. The dataset is ideal due to its small size, consisting of only 150 rows and 4 numeric attributes, which allows it to be easily handled in memory. All attributes are on the same scale, requiring no transformations before modeling. It represents a multi-class classification problem, which provides an opportunity for beginners to practice supervised learning with manageable complexity .

Multivariate plots are significant in exploring relationships between multiple variables in a dataset. They facilitate the identification of interactions and correlations between variables, which is crucial in feature selection and engineering phases of machine learning. For example, scatterplots are a type of multivariate plot that can reveal structured relationships between pairs of attributes, such as linear associations or clusters of data points, which can suggest potential predictive patterns or help refine the feature set for model building .

Statistical summaries provide a quantitative overview of dataset attributes, offering insights such as mean, median, variance, and percentiles. These summaries are beneficial in understanding data distribution, detecting anomalies, and assessing attribute significance which aids model preparation. For instance, recognizing skewed distributions may necessitate transforming data, while variance insights can guide feature scaling decisions. Such insights ensure that data is appropriately prepped and normalized before model training .

The key factors influencing the appropriate size of a dataset for machine learning include the type of problem being solved, the number of features in the data, and the type of algorithm used. The type of problem determines how complex the model needs to be, which in turn influences the amount of data required. A problem with more complexity generally needs more data to train effectively. The number of features impacts the data size because more features can require more data to ensure accurate learning and prevent overfitting. Different algorithms have varying data requirements; some algorithms, like deep learning models, typically need large datasets, while simpler models, like linear regression, may perform adequately with less data .

Visualizing data distributions aids in algorithm selection by revealing the distribution characteristics of the dataset's attributes, such as whether they follow a Gaussian distribution. If the attributes are normally distributed, algorithms that assume normality, like Linear Discriminant Analysis, can be more effective. Conversely, non-parametric algorithms, such as decision trees, may be preferable if distributions are non-Gaussian. This insight into structure and distribution informs which algorithms are best suited, enhancing model performance and accuracy .

Switching between coding environments like Jupyter and Spyder can influence data visualization by altering how complex plots are rendered and manipulated. Spyder offers an integrated development environment with features suited for creating and displaying 3D data visualizations, which might be challenging or less efficient in Jupyter's notebook interface. Choosing the appropriate environment depends on the complexity and requirements of the visualization tasks in a machine learning project .

Ensuring numeric attributes are on the same scale is important to prevent attributes with larger ranges from disproportionately influencing the model's performance, leading to skewed results. Methods to achieve consistent scaling include normalization and standardization. Normalization transforms data to a 0-1 range, while standardization shifts data to have a mean of zero and a standard deviation of one. These processes ensure equal weighting across features, yielding more accurate model predictions .

You might also like