13 Oct Machine Learning – Mean
Mean is used to get the mean i.e. the average values. It is a statistical measure that is calculated by adding the values. The result is then divided by the number of observations.
Example
Let’s say you have marks of 10 students in Mathematics subject and the average marks are to be calculated. For that, add the marks of all the students and divide by 10. This will be the mean.
Coding Example – Calculate Mean with Python
Let us see an example. To calculate the mean in Python, we will use the mean() method of the NumPy package.
The NumPy package is used for scientific computing with Python. We will also use the Pandas library to create a Pandas Dataframe. The Pandas DataFrame is a Two-dimensional tabular data structure i.e. table with rows and columns.
Read: Free NumPy Tutorial
Read: Free Pandas Tutorial
The following is the Python code to get the mean marks of 10 students:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import numpy as np import pandas as pd # create a pandas dataframe marks = pd.DataFrame({ 'student_rollno': ['0001', '0002', '0003', '0004', '0005', '0006', '0007', '0008', '0009', '0010'], 'student_marks': [96, 83, 90, 87, 67, 60, 75, 80, 77, 70] }) # get the mean mean_marks = np.mean(marks['student_marks']) print('Mean marks of students:', mean_marks) |
The following is the output;
1 2 3 |
Mean marks of students: 78.5 |
Let us now see what is a median with an example.
If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.
For Videos, Join Our YouTube Channel: Join Now
Read More:
- What is Machine Learning
- What is a Machine Learning Model
- Types of Machine Learning
- Supervised vs Unsupervised vs Reinforcement Machine Learning
- What is Deep Learning
- Feedforward Neural Networks (FNN)
- Convolutional Neural Network (CNN)
- Recurrent Neural Networks (RNN)
- Long short-term memory (LSTM)
- Generative Adversarial Networks (GANs)
No Comments