├── Datasets_Working.py ├── Functional Calculator.py ├── Iris_svm_SVC_linear.py ├── Iris_svm_SVC_poly.py ├── Iris_svm_SVC_rbf.py ├── Irisdata_GaussianNB.py ├── Irisdataset_LogisticRegression.py ├── Irisdataset_svm_SVC_sigmoid.py ├── LabTask_jpg_to_PNG.py ├── Lab_Task_jpg_to_sketch.py ├── Machine Learning Model Name.docx ├── Task#10Introduction to Numpy.py ├── Task#11_Linear Alegbra with Numpy, Statistical Functions with Numpy.py ├── Task#12_Broadcasting in Numpy Array.py ├── Task#13_Starting with Pandas.py ├── Task#14_Loading Data with Pandas.py ├── iris_DecisionTreeClassifier.py ├── iris_RandomForestClassifier.py ├── logistic_Regression_withGraphMaltplot.py ├── neighbors_Centriod.py └── rainfall_dataset_LogisticRegression.py /Datasets_Working.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[15]: 5 | 6 | 7 | import os 8 | import pandas as pd 9 | import numpy as np 10 | 11 | 12 | # In[16]: 13 | 14 | 15 | os.chdir("C:\\python\\") 16 | os.getcwd() 17 | 18 | 19 | # In[30]: 20 | 21 | 22 | ds = pd.read_csv("abc.csv") 23 | ds 24 | 25 | 26 | # In[58]: 27 | 28 | 29 | x=ds.iloc[:,0:4].values 30 | x 31 | 32 | 33 | # In[76]: 34 | 35 | 36 | y=ds.iloc[:,4].values 37 | y 38 | 39 | 40 | # In[83]: 41 | 42 | 43 | from sklearn.preprocessing import LabelEncoder 44 | 45 | 46 | # In[84]: 47 | 48 | 49 | le = LabelEncoder() 50 | 51 | 52 | # In[85]: 53 | 54 | 55 | y = le.fit_transform(y) 56 | 57 | 58 | # In[86]: 59 | 60 | 61 | y 62 | 63 | 64 | # In[87]: 65 | 66 | 67 | from sklearn.model_selection import train_test_split 68 | 69 | 70 | # In[120]: 71 | 72 | 73 | x_train, x_test, y_train,y_test = train_test_split(x,y,test_size = 0.2) 74 | 75 | 76 | # In[121]: 77 | 78 | 79 | from sklearn.linear_model import LogisticRegression 80 | 81 | 82 | # In[122]: 83 | 84 | 85 | lgm = LogisticRegression() 86 | 87 | 88 | # In[123]: 89 | 90 | 91 | lgm.fit(x_train, y_train) 92 | 93 | 94 | # In[124]: 95 | 96 | 97 | y_Pred = lgm.predict(x_test) 98 | 99 | 100 | # In[125]: 101 | 102 | 103 | from sklearn.metrics import confusion_matrix 104 | 105 | 106 | # In[126]: 107 | 108 | 109 | confusion_matrix(y_test, y_Pred) 110 | 111 | 112 | # In[127]: 113 | 114 | 115 | 1/2 116 | 117 | 118 | # In[ ]: 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /Functional Calculator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[2]: 5 | 6 | 7 | import tkinter as tk 8 | from tkinter import messagebox 9 | 10 | def on_button_click(key): 11 | current = entry.get() 12 | if key == "=": 13 | try: 14 | result = eval(current) 15 | entry.delete(0, tk.END) 16 | entry.insert(tk.END, str(result)) 17 | except Exception as e: 18 | messagebox.showerror("Error", "Invalid Input") 19 | elif key == "C": 20 | entry.delete(0, tk.END) 21 | elif key == "DEL": 22 | entry.delete(len(current)-1) 23 | else: 24 | entry.insert(tk.END, key) 25 | 26 | root = tk.Tk() 27 | root.title("Calculator") 28 | root.geometry("300x400") 29 | 30 | entry = tk.Entry(root, font=("Helvetica", 20), justify="right", bd=10) 31 | entry.grid(row=0, column=0, columnspan=4, sticky="nsew", padx=5, pady=5) 32 | 33 | buttons = [ 34 | ("7", 1, 0), ("8", 1, 1), ("9", 1, 2), ("DEL", 1, 3), 35 | ("4", 2, 0), ("5", 2, 1), ("6", 2, 2), ("+", 2, 3), 36 | ("1", 3, 0), ("2", 3, 1), ("3", 3, 2), ("-", 3, 3), 37 | ("0", 4, 0), (".", 4, 1), ("/", 4, 2), ("*", 4, 3), 38 | ("C", 5, 0), ("(", 5, 1), (")", 5, 2), ("=", 5, 3), 39 | ] 40 | 41 | for (text, row, col) in buttons: 42 | btn = tk.Button(root, text=text, font=("Helvetica", 14), command=lambda key=text: on_button_click(key), bd=5) 43 | btn.grid(row=row, column=col, sticky="nsew", padx=5, pady=5) 44 | 45 | for i in range(6): 46 | root.rowconfigure(i, weight=1) 47 | 48 | for i in range(4): 49 | root.columnconfigure(i, weight=1) 50 | 51 | root.mainloop() 52 | 53 | 54 | # In[ ]: 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Iris_svm_SVC_linear.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | import os 8 | import pandas as pd 9 | import numpy as np 10 | 11 | 12 | # In[3]: 13 | 14 | 15 | os.chdir("C:\\python") 16 | os.getcwd() 17 | 18 | 19 | # In[4]: 20 | 21 | 22 | set_d = pd.read_csv("iris.csv") 23 | set_d 24 | 25 | 26 | # In[6]: 27 | 28 | 29 | x = set_d.iloc[:,:4].values 30 | x 31 | 32 | 33 | # In[7]: 34 | 35 | 36 | y = set_d.iloc[:,4].values 37 | y 38 | 39 | 40 | # In[9]: 41 | 42 | 43 | from sklearn.preprocessing import LabelEncoder 44 | 45 | 46 | # In[10]: 47 | 48 | 49 | lb_l = LabelEncoder() 50 | 51 | 52 | # In[11]: 53 | 54 | 55 | y = lb_l.fit_transform(y) 56 | y 57 | 58 | 59 | # In[12]: 60 | 61 | 62 | from sklearn.model_selection import train_test_split 63 | 64 | 65 | # In[13]: 66 | 67 | 68 | x_test, x_train, y_test, y_train = train_test_split(x,y,test_size = 0.2) 69 | 70 | 71 | # In[14]: 72 | 73 | 74 | from sklearn.svm import SVC 75 | 76 | 77 | # In[15]: 78 | 79 | 80 | classifier_svm_linear = SVC(kernel = 'linear') 81 | 82 | 83 | # In[16]: 84 | 85 | 86 | classifier_svm_linear.fit(x_train, y_train) 87 | 88 | 89 | # In[17]: 90 | 91 | 92 | y_Pred = classifier_svm_linear.predict(x_test) 93 | 94 | 95 | # In[18]: 96 | 97 | 98 | from sklearn.metrics import confusion_matrix 99 | confusion_matrix(y_test, y_Pred) 100 | 101 | 102 | # In[19]: 103 | 104 | 105 | 115/120 106 | 107 | 108 | # In[ ]: 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /Iris_svm_SVC_poly.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | import os 8 | import pandas as pd 9 | import numpy as np 10 | 11 | 12 | # In[2]: 13 | 14 | 15 | os.chdir("C:\\python") 16 | os.getcwd() 17 | 18 | 19 | # In[3]: 20 | 21 | 22 | set1 = pd.read_csv("iris.csv") 23 | set1 24 | 25 | 26 | # In[4]: 27 | 28 | 29 | x = set1.iloc[:, 0:4].values 30 | x 31 | 32 | 33 | # In[6]: 34 | 35 | 36 | y = set1.iloc[:,4].values 37 | y 38 | 39 | 40 | # In[9]: 41 | 42 | 43 | from sklearn.preprocessing import LabelEncoder 44 | 45 | 46 | # In[10]: 47 | 48 | 49 | lb_E = LabelEncoder() 50 | 51 | 52 | # In[11]: 53 | 54 | 55 | y = lb_E.fit_transform(y) 56 | y 57 | 58 | 59 | # In[12]: 60 | 61 | 62 | from sklearn.model_selection import train_test_split 63 | 64 | 65 | # In[13]: 66 | 67 | 68 | x_test, x_train, y_test, y_train = train_test_split(x,y,test_size = 0.2) 69 | 70 | 71 | # In[14]: 72 | 73 | 74 | from sklearn.svm import SVC 75 | classifier_svm_poly = SVC(kernel = 'poly') 76 | 77 | 78 | # In[15]: 79 | 80 | 81 | classifier_svm_poly.fit(x_train, y_train) 82 | 83 | 84 | # In[16]: 85 | 86 | 87 | y_Pred = classifier_svm_poly.predict(x_test) 88 | 89 | 90 | # In[17]: 91 | 92 | 93 | from sklearn.metrics import confusion_matrix 94 | confusion_matrix(y_test,y_Pred) 95 | 96 | 97 | # In[18]: 98 | 99 | 100 | 115/120 101 | 102 | 103 | # In[ ]: 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /Iris_svm_SVC_rbf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | import os 8 | import pandas as pd 9 | import numpy as np 10 | 11 | 12 | # In[2]: 13 | 14 | 15 | os.chdir("C:\\python") 16 | os.getcwd() 17 | 18 | 19 | # In[4]: 20 | 21 | 22 | se_t = pd.read_csv("iris.csv") 23 | se_t 24 | 25 | 26 | # In[6]: 27 | 28 | 29 | x = se_t.iloc[:,0:4].values 30 | x 31 | 32 | 33 | # In[7]: 34 | 35 | 36 | y = se_t.iloc[:,4].values 37 | y 38 | 39 | 40 | # In[9]: 41 | 42 | 43 | from sklearn.preprocessing import LabelEncoder 44 | lbl_1 = LabelEncoder() 45 | 46 | 47 | # In[10]: 48 | 49 | 50 | y = lbl_1.fit_transform(y) 51 | y 52 | 53 | 54 | # In[11]: 55 | 56 | 57 | from sklearn.model_selection import train_test_split 58 | 59 | 60 | # In[12]: 61 | 62 | 63 | x_test, x_train, y_test, y_train = train_test_split(x,y, test_size = 0.2) 64 | 65 | 66 | # In[13]: 67 | 68 | 69 | from sklearn.svm import SVC 70 | classifier_svm_rbf = SVC(kernel = 'rbf') 71 | classifier_svm_rbf.fit(x_train, y_train) 72 | 73 | 74 | # In[14]: 75 | 76 | 77 | y_Pred = classifier_svm_rbf.predict(x_test) 78 | 79 | 80 | # In[15]: 81 | 82 | 83 | from sklearn.metrics import confusion_matrix 84 | confusion_matrix(y_test, y_Pred) 85 | 86 | 87 | # In[16]: 88 | 89 | 90 | 96/120 91 | 92 | 93 | # In[ ]: 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /Irisdata_GaussianNB.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | import os 8 | import pandas as pd 9 | import numpy as np 10 | 11 | 12 | # In[2]: 13 | 14 | 15 | os.chdir("C:\\python") 16 | 17 | 18 | # In[4]: 19 | 20 | 21 | os.getcwd() 22 | 23 | 24 | # In[5]: 25 | 26 | 27 | d_set = pd.read_csv("iris.csv") 28 | 29 | 30 | # In[6]: 31 | 32 | 33 | d_set 34 | 35 | 36 | # In[13]: 37 | 38 | 39 | x = d_set.iloc[:,:4].values 40 | 41 | 42 | # In[14]: 43 | 44 | 45 | x 46 | 47 | 48 | # In[15]: 49 | 50 | 51 | y = d_set.iloc[:,4].values 52 | y 53 | 54 | 55 | # In[16]: 56 | 57 | 58 | from sklearn.preprocessing import LabelEncoder 59 | 60 | 61 | # In[17]: 62 | 63 | 64 | l_bl = LabelEncoder() 65 | 66 | 67 | # In[18]: 68 | 69 | 70 | y = l_bl.fit_transform(y) 71 | y 72 | 73 | 74 | # In[26]: 75 | 76 | 77 | from sklearn.model_selection import train_test_split 78 | 79 | 80 | # In[27]: 81 | 82 | 83 | x_test, x_train, y_test, y_train = train_test_split(x,y,test_size = 0.2) 84 | 85 | 86 | # In[28]: 87 | 88 | 89 | from sklearn.naive_bayes import GaussianNB 90 | classifier_NB = GaussianNB() 91 | 92 | 93 | # In[29]: 94 | 95 | 96 | classifier_NB.fit(x_train, y_train) 97 | 98 | 99 | # In[30]: 100 | 101 | 102 | y_Pred = classifier_NB.predict(x_test) 103 | 104 | 105 | # In[34]: 106 | 107 | 108 | from sklearn.metrics import confusion_matrix 109 | confusion_matrix(y_test, y_Pred) 110 | 111 | 112 | # In[35]: 113 | 114 | 115 | 113/44 116 | 117 | 118 | # In[ ]: 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /Irisdataset_LogisticRegression.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[5]: 5 | 6 | 7 | import os 8 | import pandas as pd 9 | import numpy as np 10 | 11 | 12 | # In[6]: 13 | 14 | 15 | os.chdir("C:\\python") 16 | os.getcwd() 17 | 18 | 19 | # In[7]: 20 | 21 | 22 | dataset = pd.read_csv("iris.csv") 23 | dataset 24 | 25 | 26 | # In[8]: 27 | 28 | 29 | x=dataset.iloc[:,:4].values 30 | x 31 | 32 | 33 | # In[9]: 34 | 35 | 36 | y=dataset.iloc[:,4].values 37 | y 38 | 39 | 40 | # In[10]: 41 | 42 | 43 | from sklearn.preprocessing import LabelEncoder 44 | 45 | 46 | # In[11]: 47 | 48 | 49 | lbl = LabelEncoder() 50 | 51 | 52 | # In[12]: 53 | 54 | 55 | y = lbl.fit_transform(y) 56 | y 57 | 58 | 59 | # In[13]: 60 | 61 | 62 | from sklearn.model_selection import train_test_split 63 | 64 | 65 | # In[14]: 66 | 67 | 68 | x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.2) 69 | 70 | 71 | # In[15]: 72 | 73 | 74 | from sklearn.linear_model import LogisticRegression 75 | 76 | 77 | # In[16]: 78 | 79 | 80 | lgmodel = LogisticRegression() 81 | 82 | 83 | # In[17]: 84 | 85 | 86 | lgmodel.fit(x_train, y_train) 87 | 88 | 89 | # In[18]: 90 | 91 | 92 | y_pdt = lgmodel.predict(x_test) 93 | 94 | 95 | # In[19]: 96 | 97 | 98 | from sklearn.metrics import confusion_matrix 99 | 100 | 101 | # In[20]: 102 | 103 | 104 | confusion_matrix(y_test, y_pdt) 105 | 106 | 107 | # In[21]: 108 | 109 | 110 | 28/30 111 | 112 | 113 | # In[ ]: 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /Irisdataset_svm_SVC_sigmoid.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | import os 8 | import pandas as pd 9 | import numpy as np 10 | 11 | 12 | # In[2]: 13 | 14 | 15 | os.chdir("C:\\python") 16 | os.getcwd() 17 | 18 | 19 | # In[3]: 20 | 21 | 22 | dset = pd.read_csv("iris.csv") 23 | 24 | 25 | # In[4]: 26 | 27 | 28 | dset 29 | 30 | 31 | # In[5]: 32 | 33 | 34 | x = dset.iloc[:,:4].values 35 | x 36 | 37 | 38 | # In[6]: 39 | 40 | 41 | y = dset.iloc[:,4].values 42 | y 43 | 44 | 45 | # In[7]: 46 | 47 | 48 | from sklearn.preprocessing import LabelEncoder 49 | lab_l = LabelEncoder() 50 | 51 | 52 | # In[8]: 53 | 54 | 55 | y = lab_l.fit_transform(y) 56 | y 57 | 58 | 59 | # In[9]: 60 | 61 | 62 | from sklearn.model_selection import train_test_split 63 | 64 | 65 | # In[11]: 66 | 67 | 68 | x_test, x_train, y_test, y_train = train_test_split(x,y, test_size = 0.2) 69 | 70 | 71 | # In[13]: 72 | 73 | 74 | from sklearn.svm import SVC 75 | 76 | 77 | # In[14]: 78 | 79 | 80 | classifier_svm_sigmoid = SVC(kernel = 'sigmoid') 81 | classifier_svm_sigmoid.fit(x_train, y_train) 82 | 83 | 84 | # In[16]: 85 | 86 | 87 | y_Pred = classifier_svm_sigmoid.predict(x_test) 88 | 89 | 90 | # In[19]: 91 | 92 | 93 | from sklearn.metrics import confusion_matrix 94 | confusion_matrix(y_test, y_Pred) 95 | 96 | 97 | # In[20]: 98 | 99 | 100 | 33/87 101 | 102 | 103 | # In[ ]: 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /LabTask_jpg_to_PNG.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[5]: 5 | 6 | 7 | from PIL import Image 8 | im1 = Image.open('E:\\Memories\\HEC visit with Sir Muzamil\\131ND750\\sir.JPG') 9 | im1.save('E:\\Memories\\HEC visit with Sir Muzamil\\131ND750\\new_sir.PNG') 10 | 11 | 12 | # In[ ]: 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Lab_Task_jpg_to_sketch.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[7]: 5 | 6 | 7 | import cv2 8 | 9 | # Load the image 10 | img = cv2.imread('E:\\Memories\\HEC visit with Sir Muzamil\\131ND750\\sir.JPG') 11 | 12 | # Convert the image to grayscale 13 | gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 14 | 15 | # Invert the grayscale image 16 | inverted_image = 255 - gray_image 17 | 18 | # Blur the inverted image using a Gaussian filter 19 | blurred_image = cv2.GaussianBlur(inverted_image, (21, 21), 0) 20 | 21 | # Blend the grayscale image with the blurred inverted image 22 | sketch_image = cv2.divide(gray_image, 255 - blurred_image, scale=256) 23 | 24 | # Save the sketch image 25 | cv2.imwrite('E:\\Memories\\HEC visit with Sir Muzamil\\131ND750\\new1_sir.JPG', sketch_image) 26 | 27 | 28 | # In[ ]: 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Machine Learning Model Name.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilbarhussainmalik12345/Python-projects/2edfc3b96b2d172729b9d5d6e95bb76ab11aa090/Machine Learning Model Name.docx -------------------------------------------------------------------------------- /Task#10Introduction to Numpy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[2]: 5 | 6 | 7 | #Introduction to Numpy 8 | import numpy as np 9 | x = np.array([1, 2, 3, 4]) 10 | print("Original Array:") 11 | print(x) 12 | print("Check the array have no any zero element:") 13 | print(np.all(x)) 14 | x = np.array([0, 1, 2, 3]) 15 | print("Original Array:") 16 | print(x) 17 | print("Check the array have no any zero element:") 18 | print(np.all(x)) 19 | 20 | 21 | # In[3]: 22 | 23 | 24 | #Practice of Array 25 | #Checking the size 26 | import numpy as np 27 | X = np.array([1, 7, 13, 105]) 28 | print("Original array:") 29 | print(X) 30 | print("Size of the memory occupied by the said array:") 31 | print("%d bytes" % (X.size * X.itemsize)) 32 | 33 | 34 | # In[4]: 35 | 36 | 37 | import numpy as np 38 | array=np.arange(30,71) 39 | print("Array of the integers from 30 to70") 40 | print(array) 41 | 42 | 43 | # In[5]: 44 | 45 | 46 | #Finding number of rows and columns 47 | import numpy as np 48 | m= np.arange(10,22).reshape((3, 4)) 49 | print("Original matrix:") 50 | print(m) 51 | print("Number of rows and columns of the said matrix:") 52 | print(m.shape) 53 | 54 | 55 | # In[6]: 56 | 57 | 58 | #Operations on the arrays 59 | import numpy as np 60 | arr1 = np.arange(4, dtype = np.float_).reshape(2, 2) 61 | 62 | print('First array\n:') 63 | print(arr1) 64 | 65 | print('Second array\n:') 66 | arr2 = np.array([12, 12]) 67 | print(arr2) 68 | 69 | print('Adding the two arrays\n:') 70 | print(np.add(arr1, arr2)) 71 | 72 | print('Subtracting the two array\ns:') 73 | print(np.subtract(arr1, arr2)) 74 | 75 | print('Multiplying the two arrays\n:') 76 | print(np.multiply(arr1, arr2)) 77 | 78 | print('Dividing the two arrays\n:') 79 | print(np.divide(arr1, arr2)) 80 | 81 | 82 | # In[7]: 83 | 84 | 85 | import numpy as np 86 | print("Add:") 87 | print(np.add(1.0, 4.0)) 88 | print("Subtract:") 89 | print(np.subtract(1.0, 4.0)) 90 | print("Multiply:") 91 | print(np.multiply(1.0, 4.0)) 92 | print("Divide:") 93 | print(np.divide(1.0, 4.0)) 94 | 95 | 96 | # In[ ]: 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /Task#11_Linear Alegbra with Numpy, Statistical Functions with Numpy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[3]: 5 | 6 | 7 | #Multiplication of matrix 8 | import numpy as np 9 | p = [[1, 0], [0, 1]] 10 | q = [[1, 2], [3, 4]] 11 | print("Original Matrix:--> ") 12 | print(p) 13 | print(q) 14 | result1 = np.dot(p, q) 15 | print("Result of the matrix after multiplication:--> :") 16 | print(result1) 17 | 18 | 19 | # In[6]: 20 | 21 | 22 | #NumPy program to compute the determinant of square array 23 | import numpy as np 24 | from numpy import linalg as LA 25 | a = np.array([[1, 0], [1, 2]]) 26 | print("Original 2-D array: ") 27 | print(a) 28 | print("Determinant of the 2-D array:") 29 | print(np.linalg.det(a)) 30 | 31 | 32 | # In[7]: 33 | 34 | 35 | #mean of the matrix 36 | import numpy as np 37 | a = np.array([[1, 2], [3, 4]]) 38 | b=np.mean(a) 39 | print(b) 40 | x = np.array([[5, 6], [7, 34]]) 41 | y=np.mean(x) 42 | print(y) 43 | 44 | 45 | # In[9]: 46 | 47 | 48 | #median of the matrix 49 | arr = [12, 7, 15, 8, 9, 5, 3] 50 | arr1 = np.median(arr) 51 | print(arr1) 52 | 53 | 54 | # In[11]: 55 | 56 | 57 | #mode of the matix 58 | from scipy import stats as st 59 | import numpy as np 60 | abc = np.array([1, 1, 2, 2, 2, 3, 4, 5]) 61 | 62 | print(st.mode(abc)) 63 | 64 | 65 | # In[14]: 66 | 67 | 68 | #mode also 69 | import statistics as st 70 | import numpy as np 71 | arr1 = np.array([9, 8, 7, 6, 6, 6, 6, 5, 5, 4,3, 2, 1, 1, 1, 1, 1, 1]) 72 | print(st.mode(arr1)) 73 | 74 | 75 | # In[16]: 76 | 77 | 78 | #Quartiles 79 | # numpy.quantile() method 80 | import numpy as np 81 | 82 | arr = [20, 2, 7, 1, 34] 83 | 84 | print("arr : ", arr) 85 | print("Q2 quantile of arr : ", np.quantile(arr, .25)) 86 | print("Q1 quantile of arr : ", np.quantile(arr, .40)) 87 | print("Q3 quantile of arr : ", np.quantile(arr, .80)) 88 | print("100th quantile of arr : ", np.quantile(arr, .30)) 89 | 90 | 91 | # In[21]: 92 | 93 | 94 | #Rank of the matrix 95 | 96 | import numpy 97 | 98 | array= numpy.matrix([[8,1,7],[5,2,6]]) 99 | 100 | print("Original Matrix is:--> ",array) 101 | 102 | rank=numpy.linalg.matrix_rank(array) 103 | 104 | print("Rank of the Matrix is:--> ", rank) 105 | 106 | 107 | # In[22]: 108 | 109 | 110 | #Probability Distribution 111 | from numpy import random 112 | x = random.binomial (n=6, p=0.5, size=10) 113 | print(x) 114 | 115 | 116 | # In[23]: 117 | 118 | 119 | #Finding minimum and maximmum elements of the array 120 | #Statical Functions 121 | import numpy as np 122 | arr= np.array([[1,23,78],[98,60,75],[79,25,48]]) 123 | print(arr) 124 | #Minimum Function 125 | print(np.amin(arr)) 126 | #Maximum Function 127 | print(np.amax(arr)) 128 | 129 | 130 | # In[24]: 131 | 132 | 133 | #Standard Deviation 134 | import numpy as np 135 | a = np.array([5,6,7]) 136 | print(a) 137 | print(np.std(a)) 138 | 139 | 140 | # In[ ]: 141 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /Task#12_Broadcasting in Numpy Array.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | #Broadcasting with numpy 8 | import numpy as np 9 | 10 | a = np.array([5, 7, 3, 1]) 11 | b = np.array([90, 50, 0, 30]) 12 | #For Multiplication dimensions must be same 13 | c = a * b 14 | print(c) 15 | 16 | 17 | # In[2]: 18 | 19 | 20 | import numpy as np 21 | a = np.array([17, 11, 19]) 22 | print(a) 23 | b = 3 24 | print(b) 25 | 26 | # Broadcasting happened because of 27 | # miss match in array Dimension. 28 | c = a + b 29 | print(c) 30 | 31 | 32 | # In[3]: 33 | 34 | 35 | import numpy as np 36 | A = np.array([[11, 22, 33], [10, 20, 30]]) 37 | print(A) 38 | b = 4 39 | print(b) 40 | 41 | C = A + b 42 | print(C) 43 | 44 | 45 | # In[ ]: 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Task#13_Starting with Pandas.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[3]: 5 | 6 | 7 | #Starting with pandas 8 | # importing pandas module 9 | import pandas as pd 10 | 11 | # reading csv file from url 12 | data = pd.read_csv("C:\\Users\\Professor Jordan\\Downloads\\nba.csv") 13 | 14 | # String to be searched in start of string 15 | search ="G" 16 | 17 | # boolean series returned 18 | bool_series = data["College"].str.startswith(search, na = False) 19 | 20 | 21 | # In[4]: 22 | 23 | 24 | data[bool_series] 25 | 26 | 27 | # In[5]: 28 | 29 | 30 | #Pandas series examples 31 | import pandas as pd 32 | 33 | a = [1, 7, 2] 34 | 35 | var = pd.Series(a) 36 | 37 | print(var) 38 | 39 | 40 | # In[6]: 41 | 42 | 43 | print(var[0]) 44 | 45 | 46 | # In[7]: 47 | 48 | 49 | #Creating labels 50 | import pandas as pd 51 | 52 | a = [1, 7, 2] 53 | 54 | var = pd.Series(a, index = ["x", "y", "z"]) 55 | 56 | print(var) 57 | 58 | 59 | # In[9]: 60 | 61 | 62 | #Dataframe 63 | 64 | import pandas as pd 65 | # Creating a list 66 | author = ['Dilbar', 'Hussain','Bytewise', 'Fellow'] 67 | auth_series = pd.Series(author) 68 | # Printing Series 69 | print(auth_series) 70 | 71 | 72 | # In[10]: 73 | 74 | 75 | print(type(auth_series)) 76 | 77 | 78 | # In[11]: 79 | 80 | 81 | # Importing Pandas library 82 | import pandas as pd 83 | 84 | # Creating two lists 85 | author = ['Ali', 'Khan','At', 'Sukkur'] 86 | article = [210, 211, 114, 178] 87 | # Creating two Series by passing lists 88 | auth_series = pd.Series(author) 89 | article_series = pd.Series(article) 90 | # Creating a dictionary by passing Series objects as values 91 | frame = {'Author': auth_series,'Article': article_series} 92 | # Creating DataFrame by passing Dictionary 93 | result = pd.DataFrame(frame) 94 | # Printing elements of Dataframe 95 | print(result) 96 | 97 | 98 | # In[ ]: 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /Task#14_Loading Data with Pandas.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[3]: 5 | 6 | 7 | #Reading CSV File 8 | #Starting with pandas 9 | # importing pandas module 10 | import pandas as pd 11 | 12 | # reading csv file from url 13 | data = pd.read_csv("C:\\Users\\Professor Jordan\\Downloads\\nba.csv") 14 | 15 | # String to be searched in start of string 16 | search ="G" 17 | 18 | # boolean series returned 19 | bool_series = data["College"].str.startswith(search, na = False) 20 | data[bool_series] 21 | 22 | 23 | # In[ ]: 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /iris_DecisionTreeClassifier.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[27]: 5 | 6 | 7 | import os 8 | import pandas as pd 9 | import numpy as np 10 | 11 | 12 | # In[28]: 13 | 14 | 15 | os.chdir("C:\\python") 16 | os.getcwd() 17 | 18 | 19 | # In[29]: 20 | 21 | 22 | s_et = pd.read_csv("iris.csv") 23 | s_et 24 | 25 | 26 | # In[30]: 27 | 28 | 29 | x = s_et.iloc[:,0:4].values 30 | x 31 | 32 | 33 | # In[31]: 34 | 35 | 36 | y = s_et.iloc[:, 4].values 37 | 38 | 39 | # In[32]: 40 | 41 | 42 | y 43 | 44 | 45 | # In[33]: 46 | 47 | 48 | from sklearn.preprocessing import LabelEncoder 49 | 50 | 51 | # In[34]: 52 | 53 | 54 | lbl = LabelEncoder() 55 | 56 | 57 | # In[35]: 58 | 59 | 60 | y = lbl.fit_transform(y) 61 | y 62 | 63 | 64 | # In[36]: 65 | 66 | 67 | from sklearn.model_selection import train_test_split 68 | 69 | 70 | # In[40]: 71 | 72 | 73 | x_test, x_train, y_train, y_test = train_test_split(x,y,test_size = 0.5) 74 | 75 | 76 | # In[41]: 77 | 78 | 79 | from sklearn.tree import DecisionTreeClassifier 80 | 81 | 82 | # In[42]: 83 | 84 | 85 | classifier_dt = DecisionTreeClassifier(criterion = 'entropy') 86 | 87 | 88 | # In[43]: 89 | 90 | 91 | classifier_dt.fit(x_train, y_train) 92 | 93 | 94 | # In[44]: 95 | 96 | 97 | y_Pred = classifier_dt.predict(x_test) 98 | 99 | 100 | # In[45]: 101 | 102 | 103 | from sklearn.metrics import confusion_matrix 104 | 105 | 106 | # In[46]: 107 | 108 | 109 | confusion_matrix(y_test, y_train) 110 | 111 | 112 | # In[47]: 113 | 114 | 115 | 27/84 116 | 117 | 118 | # In[ ]: 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /iris_RandomForestClassifier.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | import os 8 | import pandas as pd 9 | import numpy as np 10 | 11 | 12 | # In[2]: 13 | 14 | 15 | os.chdir("C:\\python") 16 | os.getcwd() 17 | 18 | 19 | # In[3]: 20 | 21 | 22 | se_t1 = pd.read_csv("iris.csv") 23 | se_t1 24 | 25 | 26 | # In[4]: 27 | 28 | 29 | x = se_t1.iloc[:, 0:4].values 30 | x 31 | 32 | 33 | # In[5]: 34 | 35 | 36 | y = se_t1.iloc[:,4].values 37 | y 38 | 39 | 40 | # In[6]: 41 | 42 | 43 | from sklearn.preprocessing import LabelEncoder 44 | 45 | 46 | # In[7]: 47 | 48 | 49 | l_b = LabelEncoder() 50 | 51 | 52 | # In[8]: 53 | 54 | 55 | y = l_b.fit_transform(y) 56 | y 57 | 58 | 59 | # In[9]: 60 | 61 | 62 | from sklearn.model_selection import train_test_split 63 | 64 | 65 | # In[21]: 66 | 67 | 68 | x_train, x_test, y_train, y_test = train_test_split(x,y,test_size = 0.5) 69 | 70 | 71 | # In[22]: 72 | 73 | 74 | from sklearn.ensemble import RandomForestClassifier 75 | 76 | 77 | # In[23]: 78 | 79 | 80 | classifier_rf = RandomForestClassifier(n_estimators = 3, criterion = 'entropy') 81 | 82 | 83 | # In[24]: 84 | 85 | 86 | classifier_rf.fit(x_train, y_train) 87 | 88 | 89 | # In[25]: 90 | 91 | 92 | y_Pred = classifier_rf.predict(x_test) 93 | 94 | 95 | # In[26]: 96 | 97 | 98 | from sklearn.metrics import confusion_matrix 99 | 100 | 101 | # In[27]: 102 | 103 | 104 | confusion_matrix(y_test, y_train) 105 | 106 | 107 | # 26/83 108 | 109 | # In[28]: 110 | 111 | 112 | 26/83 113 | 114 | 115 | # In[ ]: 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /logistic_Regression_withGraphMaltplot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[77]: 5 | 6 | 7 | import os 8 | import pandas as pd 9 | import numpy as np 10 | import matplotlib.pyplot as plt 11 | 12 | 13 | # In[78]: 14 | 15 | 16 | os.chdir('C:\\python') 17 | os.getcwd() 18 | 19 | 20 | # In[79]: 21 | 22 | 23 | dataset = pd.read_csv('iris.csv') 24 | dataset 25 | 26 | 27 | # In[80]: 28 | 29 | 30 | x = np.array([0,5]) 31 | y = np.array([0, 150]) 32 | 33 | 34 | # In[81]: 35 | 36 | 37 | plt.plot(x, y) 38 | plt.show() 39 | 40 | 41 | # In[82]: 42 | 43 | 44 | x = dataset.iloc[:, :4].values 45 | x 46 | 47 | 48 | # In[83]: 49 | 50 | 51 | y = dataset.iloc[:,4].values 52 | y 53 | 54 | 55 | # In[84]: 56 | 57 | 58 | from sklearn.preprocessing import LabelEncoder 59 | 60 | 61 | # In[85]: 62 | 63 | 64 | label = LabelEncoder() 65 | 66 | 67 | # In[86]: 68 | 69 | 70 | y = label.fit_transform(y) 71 | y 72 | 73 | 74 | # In[87]: 75 | 76 | 77 | from sklearn.model_selection import train_test_split 78 | 79 | 80 | # In[88]: 81 | 82 | 83 | x_train, x_test, y_train, y_test = train_test_split(x,y, test_size = 0.2) 84 | 85 | 86 | # In[89]: 87 | 88 | 89 | from sklearn.linear_model import LogisticRegression 90 | 91 | 92 | # In[90]: 93 | 94 | 95 | lmdl = LogisticRegression() 96 | 97 | 98 | # In[91]: 99 | 100 | 101 | lmdl.fit(x_train, y_train) 102 | 103 | 104 | # In[92]: 105 | 106 | 107 | y_prdt = lmdl.predict(x_test) 108 | 109 | 110 | # In[93]: 111 | 112 | 113 | from sklearn.metrics import confusion_matrix 114 | 115 | 116 | # In[94]: 117 | 118 | 119 | confusion_matrix(y_test, y_prdt) 120 | 121 | 122 | # In[95]: 123 | 124 | 125 | y_test = np.array([0,3]) 126 | 127 | 128 | # In[96]: 129 | 130 | 131 | y_prdt = np.array([0, 3]) 132 | 133 | 134 | # In[97]: 135 | 136 | 137 | plt.plot(y_test, y_prdt) 138 | plt.show 139 | 140 | 141 | # In[98]: 142 | 143 | 144 | cm = confusion_matrix(y_test, y_prdt) 145 | # compute the diagonal sum of the confusion matrix using NumPy 146 | diagonal_sum = np.trace(cm) 147 | total_sum = np.sum(cm) 148 | 149 | accuracy = diagonal_sum / total_sum 150 | print("Diagonal sum",diagonal_sum) 151 | print("Diagonal Sum/ Total Sum",accuracy) 152 | #28/30 153 | 154 | 155 | # In[ ]: 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /neighbors_Centriod.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | import numpy as np 8 | import os 9 | import pandas as pd 10 | 11 | 12 | # In[2]: 13 | 14 | 15 | os.chdir("C:\\python\\") 16 | os.getcwd() 17 | 18 | 19 | # In[4]: 20 | 21 | 22 | data_set = pd.read_csv("iris.csv") 23 | data_set 24 | 25 | 26 | # In[5]: 27 | 28 | 29 | x = data_set.iloc[:,:4].values 30 | x 31 | 32 | 33 | # In[6]: 34 | 35 | 36 | y = data_set.iloc[:,4].values 37 | y 38 | 39 | 40 | # In[7]: 41 | 42 | 43 | from sklearn.preprocessing import LabelEncoder 44 | 45 | 46 | # In[8]: 47 | 48 | 49 | lbl = LabelEncoder() 50 | 51 | 52 | # In[9]: 53 | 54 | 55 | y = lbl.fit_transform(y) 56 | y 57 | 58 | 59 | # In[10]: 60 | 61 | 62 | from sklearn.model_selection import train_test_split 63 | 64 | 65 | # In[11]: 66 | 67 | 68 | x_train, x_test, y_train, y_test = train_test_split(x,y, test_size = 0.2) 69 | 70 | 71 | # In[12]: 72 | 73 | 74 | from sklearn.neighbors import NearestCentroid 75 | 76 | 77 | # In[13]: 78 | 79 | 80 | clf = NearestCentroid() 81 | 82 | 83 | # In[14]: 84 | 85 | 86 | clf.fit(x_train, y_train) 87 | 88 | 89 | # In[16]: 90 | 91 | 92 | y_pred = clf.predict(x_test) 93 | 94 | 95 | # In[17]: 96 | 97 | 98 | from sklearn.metrics import confusion_matrix 99 | 100 | 101 | # In[18]: 102 | 103 | 104 | confusion_matrix(y_test, y_pred) 105 | 106 | 107 | # In[21]: 108 | 109 | 110 | cm = confusion_matrix(y_test, y_pred) 111 | # compute the diagonal sum of the confusion matrix using NumPy 112 | diagonal_sum = np.trace(cm) 113 | total_sum = np.sum(cm) 114 | 115 | accuracy = diagonal_sum / total_sum 116 | print("Diagonal sum:--> ",diagonal_sum) 117 | print("Diagonal Sum/ Total Sum:--> ",accuracy) 118 | 119 | 120 | # In[ ]: 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /rainfall_dataset_LogisticRegression.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[51]: 5 | 6 | 7 | import os 8 | import pandas as pd 9 | import numpy as np 10 | 11 | 12 | # In[52]: 13 | 14 | 15 | os.chdir("C:\\python") 16 | 17 | 18 | # In[53]: 19 | 20 | 21 | os.getcwd() 22 | 23 | 24 | # In[54]: 25 | 26 | 27 | da_set = pd.read_csv("rainfall_pak.csv") 28 | da_set 29 | 30 | 31 | # In[55]: 32 | 33 | 34 | x = da_set.iloc[:,:2].values 35 | x 36 | 37 | 38 | # In[56]: 39 | 40 | 41 | y = da_set.iloc[:,2].values 42 | y 43 | 44 | 45 | # In[57]: 46 | 47 | 48 | from sklearn.preprocessing import LabelEncoder 49 | 50 | 51 | # In[58]: 52 | 53 | 54 | label = LabelEncoder() 55 | 56 | 57 | # In[59]: 58 | 59 | 60 | y = label.fit_transform(y) 61 | 62 | 63 | # In[60]: 64 | 65 | 66 | y 67 | 68 | 69 | # In[61]: 70 | 71 | 72 | from sklearn.model_selection import train_test_split 73 | 74 | 75 | # In[62]: 76 | 77 | 78 | x_test, x_train, y_test, y_train = train_test_split(x,y,test_size = 0.2) 79 | 80 | 81 | # In[63]: 82 | 83 | 84 | from sklearn.linear_model import LogisticRegression 85 | 86 | 87 | # In[64]: 88 | 89 | 90 | lo_mdl = LogisticRegression() 91 | 92 | 93 | # In[65]: 94 | 95 | 96 | lo_mdl.fit(x_train, y_train) 97 | 98 | 99 | # In[66]: 100 | 101 | 102 | y_pred = lo_mdl.predict(x_test) 103 | 104 | 105 | # In[67]: 106 | 107 | 108 | from sklearn.metrics import confusion_matrix 109 | 110 | 111 | # In[68]: 112 | 113 | 114 | confusion_matrix(y_test, y_pred) 115 | 116 | 117 | # In[70]: 118 | 119 | 120 | cm = confusion_matrix(y_test, y_pred) 121 | # compute the diagonal sum of the confusion matrix using NumPy 122 | diagonal_sum = np.trace(cm) 123 | total_sum = np.sum(cm) 124 | 125 | accuracy = diagonal_sum / total_sum 126 | print("Diagonal sum",diagonal_sum) 127 | print("Total Sum", total_sum) 128 | print("Diagonal Sum/ Total Sum",accuracy) 129 | 130 | 131 | # In[ ]: 132 | 133 | 134 | 135 | 136 | --------------------------------------------------------------------------------