Start Journey of Machine Learning

#Blog1

Introduction

On July 22nd, I started writing blogs on Machine learning to improve my Machine Learning skills very much. I will also share my full journey related to ML in the upcoming blogs and give you valuable content to learn Machine Learning.

So, Let's get Started...

First of all, I want to clarify a thought, many think machine learning is a very hard concept and so boring field. Due to that, beginners lose their patience at the start of the journey as they face so many mathematical terms and concepts. That's why they left this field and said this is a very tough field.

But I suggest that there may be a fall point in the path of this journey not in it but also in our life's journey. So, at that time, it is required to maintain consistency and patience throughout the whole journey with the hope that there will be a peak point in the next step and as you reach and keeps stabilizing at the peak point of the journey, you will feel a kind of satisfaction which can't you tell in the words.

Setup the Environment for Code

For coding, We required a place where our code can run and execute and show results to us. For that purpose, there are so many IDEs i.e., Integrated Development Environments. IDEs provide an environment consolidated for the programmer to write a computer program and edit and fix it.

For example, Microsoft Visual Studio, Eclipse, etc.

So, according to your computer and software requirements install them. But this will not be enough to start the code of Machine learning, we require a code editor for the same. On the internet, there are so many code editors, like, Visual Studio Code, Sublime, etc. So, install any one of them to start the code according to your convenience.

After installing them, install Jupyter Notebook on your system. For the installation of jupyter notebook, you can also install Anakonda or directly install an extension of it and start directly the code editors. Now, you are completely set up to start the code of Machine Learning.

If your computer doesn't meet the requirements of the software, you can go with online compilers, like Google Colab, Replit, etc. These online platforms provide the service of so much software to run and save your code.

Requirements for the Machine Learning

For machine learning, we require to learn some Python libraries like

  • Numpy

  • Pandas

  • Matplotlib

  • Scikit-learn, etc.

These libraries facilitate writing algorithms fastly and run the code very fastly in comparison to writing the code of that operation. Also, we do not require to know very hard mathematics as all concepts of mathematics are pre-written in the libraries. Here the requirement is just to use them. So, we first start learning these libraries by solving problems.

Learn Numpy

Some functions

  1. np.all()
    This function facilitates returning whether all the elements of the array are true or not. If any of the elements of the array return false. The final answer will be false.

     # Check if all elements from the following arrays return the logical 
     # value True
    
     import numpy as np
    
     A = np.array([[3, 2, 1, 4],
                   [5, 2, 1, 6]])
    
     B = np.array([[3, 2, 1, 4],
                   [5, 2, 0, 6]])
    
     C = np.array([[True, False, False],
                   [True, True, True]])
    
     D = np.array([0.1, 0.3])
    
     # <---- Write your code here ---->
    
     # Method 1
    
     print("A: ", end="")
     print(np.all(A))
    
     print("B: ", end="")
     print(np.all(B))
    
     print("C: ", end="")
     print(np.all(C))
    
     print("D: ", end="")
     print(np.all(D))
    
     # Method 2
    
     for name, array in zip(list('ABCD'), [A, B, C, D]):
         print(f'{name}: {np.all(array)}')
    
     '''
     The output of the Program will be:
     A: True
     B: False
     C: False
     D: True
     '''
    
  2. Attributes of np.all() function
    This function takes an array as the first argument and an axis as the second argument but by default, the axis is 0.

     # Check if all elements from the following arrays return the logical value 
     # True along the axis with index 1
    
     import numpy as np
    
     A = np.array([[3, 2, 1, 4],
                   [5, 2, 1, 6]])
    
     B = np.array([[3, 2, 1, 4],
                   [5, 2, 0, 6]])
    
     C = np.array([[True, False, False],
                   [True, True, True]])
    
     # <---- Write your code here ---->
    
     for name, array in zip(list('ABC'), [A, B, C]):
         print(f'{name}: {np.all(array, axis=1)}')
    
     '''
     The output of the program will be:
     A: [True True]
     B: [True False]
     C: [False True]
     '''
    
  3. np.any()
    This function is just opposite the np.all() function as if any of the elements of the array return true, the final answer will be true.

     # Check if any element of the following arrays returns the logical 
     # value True
    
     import numpy as np
    
     A = np.array([[0, 0, 0],
                   [0, 0, 0]])
    
     B = np.array([[0, 0, 0],
                   [0, 1, 0]])
    
     C = np.array([[False, False, False],
                   [True, False, False]])
    
     D = np.array([[0.1, 0.0]])
    
     # <---- Write your code here ---->
    
     for name, array in zip(list('ABCD'), [A, B, C, D]):
         print(f'{name}: {np.any(array)}')
    
     '''
     The output of the program will be:
     A: False
     B: True
     C: True
     D: True
     '''
    
  4. Attributes of np.any() function
    Similar to np.all() function, This function also takes an array as the first argument and an axis as the second argument but by default, the axis is 0.

     # Check if any element of the following arrays returns the logical value 
     # True along the axis with index 0
    
     import numpy as np
    
     A = np.array([[0, 0, 0],
                   [0, 0, 0]])
    
     B = np.array([[0, 0, 0],
                   [0, 1, 0]])
    
     C = np.array([[False, False, False],
                   [True, False, False]])
    
     D = np.array([[0.1, 0.0]])
    
     # <---- Write your code here ---->
    
     for name, array in zip(list('ABCD'), [A, B, C, D]):
         print(f'{name}: {np.any(array, axis=0)}')
    
     '''
     The output of the program will be:
     A: [False False False]
     B: [False True False]
     C: [True False False]
     D: [True False]
     '''
    
  5. np.isnan()
    This function is used to check whether is there any null value present in the dataset or array. If present, the function returns true otherwise returns false.

     # Check if the following array has missing data (np.nan)
    
     import numpy as np
    
     A = np.array([[3, 2, 1, np.nan],
                   [5, np.nan, 1, 6]])
    
     # <---- Write your code here ---->
    
     print(np.isnan(A))
    
     '''
     The output of the program will be:
     A: [[False False False True],
         [False True False False]]
    

Learn Pandas

Some Functions

  1. pd.Series()
    This function is used to convert the entered 1-Dimensional array into a series.

     # create a Series object and print it to the console
    
     import pandas as pd
    
     stocks = ['PLW', 'CDR', '11B', 'TEN']
    
     # <---- Write your code here ---->
    
     print(pd.Series(data=stocks))
    
     '''
     The output of the program will be:
     0  PLW
     1  CDR
     2  11B
     3  TEN
     dtype: object
     '''
    
  2. Another way to create a Series with specified indexes

     # create a Series object and assign it to the quotations variable. 
     # In response, print quotations variable to the console
    
     import pandas as pd
    
     stocks = {'PLW': 387.00, 'CDR': 339.5, 'TEN': 349.5, '11B': 391.0}
    
     # <---- Write your code here ---->
    
     quotations = pd.Series(data=stocks)
     print(quotations)
    
     '''
     The output of the program will be:
     PLW  387.0
     CDR  339.5
     TEN  349.5
     11B  391.0
     dtype: float64
     '''
    
  3. Convert Series into the list using 'tolist()' function

     # Convert quotations to the list and print it to the console.
    
     import pandas as pd
    
     stocks = {'PLW': 387.00, 'CDR': 339.5, 'TEN': 349.5, '11B': 391.0}
     quotations = pd.Series(data=stocks)
    
     # <---- Write your code here ---->
    
     quotations = quotations.tolist()
    
     print(quotations)
    
     '''
     The output of the program will be:
     [387.0 339.5 349.5 391.0]
     '''
    
  4. Create a DataFrame and assign it a specified column name

     # Convert the quotations to the DataFrame and set the column name to 
     # 'price'. In response, print this DataFrame to the console.
    
     import pandas as pd
    
     stocks = {'PLW': 387.00, 'CDR': 339.5, 'TEN': 349.5, '11B': 391.0}
     quotations = pd.Series(data=stocks)
    
     # <---- Write your code here ---->
    
     quotations = pd.DataFrame(quotations, columns=['price'])
     print(quotations)
    
     '''
     The output of the program will be:
          price
     PLW  387.0
     CDR  339.5
     TEN  349.5
     11B    391.0
     '''
    
  5. Create a Series using numpy and pandas both libraries

     '''Using the numpy and pandas create the following Series:
    
     101    10.0
     102    20.0
     103    30.0
     104    40.0
     105    50.0
     106    60.0
     107    70.0
     108    80.0
     109    90.0
     dtype: float64
    
     In response, print this Series to the console.'''
    
     import numpy as np
     import pandas as pd
    
     # <---- Write your code here ---->
    
     # Method 1
     x = np.arange(101, 110, 1)
     y = np.arange(10.0, 100.0, 10.0)
    
     s = pd.Series(y, x, float)
    
     print(s)
    
     # Method 2
     s = pd.Series(
         data=np.arange(10, 100, 10), 
         index=np.arange(101, 110), 
         dtype='float'
     )
    
     print(s)
    

Learn Matplotlib

To learn about matplotlib library, you can refer to my Jupyter notebook on GitHub.

Exercise 1 of Matplotlib.

Conclusion

Now, let's wrap this blog here, On this blog we have learned so many functions of Numpy, Pandas, and Matplotlib library. We are also keeping our journey continuing as there will be no end to the journey. This is just a fact.

Thanks for reading this blog.

If you feel this is beneficial to you somewhere, please like and comment on it.

Ok, we will come up with the next blog very fastly.