Skip to content

Commit a0df922

Browse files
Adding important python libraries codeiiest-dev#3
1 parent 03b5275 commit a0df922

File tree

12 files changed

+394
-0
lines changed

12 files changed

+394
-0
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Important Python Libraries
2+
3+
## Introduction
4+
5+
Python machine learning libraries have grown to become the most preferred language for machine learning algorithm implementations. Let’s have a look at the main Python libraries used for machine learning. 1. Some important properties of the function are:
6+
7+
- [NumPy](./numpy.md)
8+
- [Matplotlib](./matplotlib.md)
9+
- [Pandas](./pandas.md)
10+
- [Scikit-learn](./Scikit-learn.md)
11+
- [Scipy](./SciPy.md)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# 2. Matplotlib
2+
3+
Matplotlib is one of the most powerful tools for ***data visualization*** in Python.
4+
5+
***Data visualization*** the practice of visualizing data in graphs, icons, presentations and more. It is most commonly used to translate complex data into digestible insights for a non-technical audience.
6+
7+
So basically it allows us to create figures and plots, and makes it very easy to produce static raster or vector files without the need for any GUIs.
8+
9+
**Import Syntax**
10+
```py
11+
import matplotlib.pyplot as plt
12+
```
13+
14+
### **Functional Approach**
15+
Using the basic Matplotlib command, we can easily create a plot. Let’s plot an example using two arrays x and y :
16+
17+
```py
18+
#create data for plotting
19+
x = [0,1,2,3,4,5]
20+
y = [0,1,4,9,16,25]
21+
#the default graph style for plot is a line
22+
plt.plot(x, y)
23+
#display the graph
24+
plt.show
25+
```
26+
Output :
27+
28+
![title](Capture.PNG)
29+
30+
Now that we have a plot, let’s go on to name the x-axis, y-axis, and add a title using .xlabel(), .ylabel() and .title() using:
31+
32+
```py
33+
plt.title('First Plot')
34+
plt.xlable('x-axis')
35+
plt.ylable('y-axis')
36+
```
37+
38+
### **Bar Graphs**
39+
40+
When using a bar graph, the change in code will be from plt.plot() to plot.bar() changes it into a bar chart.
41+
42+
```py
43+
#create data for plotting
44+
x = [5,6,3,7,2]
45+
y = ["A", "B", "C", "D", "E"]
46+
plt.bar(y,x, color = "green")
47+
plt.show()
48+
```
49+
Output :
50+
51+
![title](1.PNG)
52+
53+
Graph can also be flipped horizontally by adding an "h" after bar.
54+
```py
55+
#create data for plotting
56+
x = [5,6,3,7,2]
57+
y = ["A", "B", "C", "D", "E"]
58+
plt.barh(y,x, color = "yellowgreen")
59+
plt.show()
60+
```
61+
Output :
62+
63+
![title](2.PNG)
64+
65+
66+
### **Scatter Plot**
67+
A scatter plot is a diagram where each value in the data set is represented by a dot.
68+
69+
```py
70+
#create data for plotting
71+
x_values = [0,1,2,3,4,5]
72+
squares = [0,1,4,9,16,25]
73+
plt.scatter(x_values,squares, s=10, color = "pink")
74+
plt.show()
75+
```
76+
Output:
77+
78+
![title](3.PNG)
79+
80+
### **Histograms**
81+
82+
A histogram is basically used to represent data provided in a form of some groups.It is accurate method for the graphical representation of numerical data distribution.It is a type of bar plot where X-axis represents the bin ranges while Y-axis gives information about frequency.
83+
84+
***Bin*** is an argument specific to a histogram and allows the user to customize how many bins they want.
85+
86+
```py
87+
x = [2,1,6,4,2,4,8,9,4,2,4,10,6,4,5,7,7,3,2,7,5,3,5,9,2,1]
88+
#plot for a histogram
89+
plt.hist(x, bins = 10, color='blue', alpha=0.5)
90+
plt.show()
91+
```
92+
Output :
93+
94+
![title](4.PNG)
95+
96+
## References
97+
- [More on](http://index-of.co.uk/Tutorials/Matplotlib%20for%20Python%20Developers.pdf)
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# 1. NumPy
2+
3+
NumPy is a well known general-purpose array-processing package. Used for large multi-dimensional array and matrix processing, with the help of a large collection of high-level mathematical functions.NumPy is very useful for handling linear algebra, Fourier transforms, and random numbers.
4+
5+
**Import Syntax**
6+
```py
7+
import numpy as np
8+
9+
#Creating an array object
10+
array = np.array([
11+
[1, 2, 3, 5, 6],
12+
[2, 1, 5, 6, 7]
13+
])
14+
```
15+
16+
**Important Function**
17+
```py
18+
#Print array dimension using array.ndim
19+
print("No. of dimensions of the array: ", array.ndim, end="\n")
20+
21+
#Print array size using array.size
22+
print("Size of the array: ", array.size, end="\n")
23+
24+
#Print array shape
25+
print("Shape of the array: ", array.shape)
26+
```
27+
Output :
28+
```
29+
No. of dimensions of the array: 2
30+
Size of the array: 10
31+
Shape of the array: (2, 5)
32+
```
33+
34+
### **Creating NumPy Arrays**
35+
36+
Arrays in NumPy can be created in multiple ways, with various number of Ranks, defining the size of the Array.
37+
38+
```py
39+
#Creating a rank 1 array by passing one python list
40+
list = [1, 2, 3, 5, 6]
41+
array = np.array(list)
42+
print(array)
43+
```
44+
Output :
45+
```
46+
[1 2 3 5 6]
47+
```
48+
```py
49+
#Creating a rank 2 array by passing two python lists
50+
list1 = [1, 2, 3, 5, 6]
51+
list2 = [3, 1, 4, 5, 1]
52+
array = np.array(
53+
[list1, list2]
54+
)
55+
print(array)
56+
```
57+
Output :
58+
```
59+
[[1 2 3 5 6]
60+
[3 1 4 5 1]]
61+
```
62+
```py
63+
#Creating a constant value array of complex type using np.full( )
64+
array = np.full((2, 2), 4, dtype='complex')
65+
print(array)
66+
```
67+
Output :
68+
```
69+
[[4.+0.j 4.+0.j ]
70+
[4.+0.j 4.+0.j ]]
71+
```
72+
### **Basic slicing and indexing in a multidimensional array**
73+
Slicing and indexing in a multidimensional array are a little bit tricky compared to slicing and indexing in a one-dimensional array.
74+
```py
75+
array = np.array([
76+
[2, 4, 5, 6],
77+
[3, 1, 6, 9],
78+
[4, 5, 1, 9],
79+
[2, 9, 1, 7]
80+
])
81+
82+
# Slicing and indexing in 4x4 array
83+
# Print first two rows and first two columns
84+
print("\n", array[0:2, 0:2])
85+
86+
# Print all rows and last two columns
87+
print("\n", array[:, 2:4])
88+
89+
# Print all column but middle two rows
90+
print("\n", array[1:3, :])
91+
```
92+
Output:
93+
```
94+
[[2 4]
95+
[3 1]]
96+
97+
[[5 6]
98+
[6 9]
99+
[1 9]
100+
[1 7]]
101+
102+
[[3 1 6 9]
103+
[4 5 1 9]]
104+
```
105+
### **NumPy Operations on Array**
106+
107+
In NumPy, arrays allow various operations that can be performed on a particular array or a combination of Arrays.These operations include some basic Mathematical operations as well as Unary and Binary operations.
108+
109+
Examples :
110+
111+
```py
112+
array = np.array([
113+
[2, 4, 5],
114+
[3, 1, 6]
115+
])
116+
117+
#Adding 5 to every element in array1
118+
newArray = array + 5
119+
print(newArray)
120+
```
121+
Output :
122+
```
123+
[[ 7 9 10]
124+
[ 8 6 11]]
125+
```
126+
```py
127+
#Multiplying 2 to every element in array2
128+
newArray = array * 2
129+
print(newArray)
130+
```
131+
Output:
132+
```
133+
[[ 4 8 10]
134+
[ 6 2 12]]
135+
```
136+
## References
137+
- [More on](https://numpy.org/doc/)

0 commit comments

Comments
 (0)