test-graph2 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: test-graph2
3
+ Version: 0.1.0
4
+ Summary: AI and ML practical codes
5
+ Author: Aquif Shaikh
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: scikit-learn
9
+ Requires-Dist: matplotlib
10
+ Requires-Dist: numpy
11
+
12
+ # test-graph2
13
+
14
+ AI & Machine Learning practical codes:
15
+ - `PR01(BFS).py`
16
+ - `PR01(IDFS).py`
17
+ - `PR02(A star).py`
18
+ - `PR05(Adaboost).py`
19
+ - `PR07(KNN).py`
20
+ - `PR08(SVM).py`
21
+
22
+ ## Usage
23
+
24
+ ```bash
25
+ pip install test-graph2
26
+ get-practicals
27
+ ```
@@ -0,0 +1,16 @@
1
+ # test-graph2
2
+
3
+ AI & Machine Learning practical codes:
4
+ - `PR01(BFS).py`
5
+ - `PR01(IDFS).py`
6
+ - `PR02(A star).py`
7
+ - `PR05(Adaboost).py`
8
+ - `PR07(KNN).py`
9
+ - `PR08(SVM).py`
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ pip install test-graph2
15
+ get-practicals
16
+ ```
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "test-graph2"
7
+ version = "0.1.0"
8
+ authors = [
9
+ { name="Aquif Shaikh" },
10
+ ]
11
+ description = "AI and ML practical codes"
12
+ readme = "README.md"
13
+ requires-python = ">=3.8"
14
+ dependencies = [
15
+ "scikit-learn",
16
+ "matplotlib",
17
+ "numpy",
18
+ ]
19
+
20
+ [project.scripts]
21
+ get-practicals = "test_mod.cli:main"
22
+
23
+ [tool.setuptools.packages.find]
24
+ where = ["."]
25
+ include = ["test_mod*"]
26
+
27
+ [tool.setuptools.package-data]
28
+ "test_mod" = ["files/*.py"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,23 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="test-graph2",
5
+ version="0.1.0",
6
+ author="Aquif Shaikh",
7
+ description="AI and ML practical codes",
8
+ packages=find_packages(),
9
+ package_data={
10
+ "test_mod": ["files/*.py"],
11
+ },
12
+ include_package_data=True,
13
+ entry_points={
14
+ "console_scripts": [
15
+ "get-practicals=test_mod.cli:main",
16
+ ],
17
+ },
18
+ install_requires=[
19
+ "scikit-learn",
20
+ "matplotlib",
21
+ "numpy",
22
+ ],
23
+ )
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: test-graph2
3
+ Version: 0.1.0
4
+ Summary: AI and ML practical codes
5
+ Author: Aquif Shaikh
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: scikit-learn
9
+ Requires-Dist: matplotlib
10
+ Requires-Dist: numpy
11
+
12
+ # test-graph2
13
+
14
+ AI & Machine Learning practical codes:
15
+ - `PR01(BFS).py`
16
+ - `PR01(IDFS).py`
17
+ - `PR02(A star).py`
18
+ - `PR05(Adaboost).py`
19
+ - `PR07(KNN).py`
20
+ - `PR08(SVM).py`
21
+
22
+ ## Usage
23
+
24
+ ```bash
25
+ pip install test-graph2
26
+ get-practicals
27
+ ```
@@ -0,0 +1,18 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.py
4
+ test_graph2.egg-info/PKG-INFO
5
+ test_graph2.egg-info/SOURCES.txt
6
+ test_graph2.egg-info/dependency_links.txt
7
+ test_graph2.egg-info/entry_points.txt
8
+ test_graph2.egg-info/requires.txt
9
+ test_graph2.egg-info/top_level.txt
10
+ test_mod/__init__.py
11
+ test_mod/__main__.py
12
+ test_mod/cli.py
13
+ test_mod/files/PR01(BFS).py
14
+ test_mod/files/PR01(IDFS).py
15
+ test_mod/files/PR02(A star).py
16
+ test_mod/files/PR05(Adaboost).py
17
+ test_mod/files/PR07(KNN).py
18
+ test_mod/files/PR08(SVM).py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ get-practicals = test_mod.cli:main
@@ -0,0 +1,3 @@
1
+ scikit-learn
2
+ matplotlib
3
+ numpy
@@ -0,0 +1 @@
1
+ test_mod
@@ -0,0 +1,3 @@
1
+ from .cli import extract_files
2
+
3
+ __all__ = ["extract_files"]
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
@@ -0,0 +1,30 @@
1
+ import os
2
+ import shutil
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ def extract_files(destination=None):
7
+ if destination is None:
8
+ destination = os.getcwd()
9
+
10
+ files_dir = Path(__file__).parent / "files"
11
+ if not files_dir.exists():
12
+ print("Error: Practical files directory not found.")
13
+ return
14
+
15
+ created_files = []
16
+ for file_path in files_dir.glob("*.py"):
17
+ dest_file = Path(destination) / file_path.name
18
+ shutil.copy2(file_path, dest_file)
19
+ created_files.append(file_path.name)
20
+ print(f" [+] Created: {file_path.name}")
21
+
22
+ print(f"\n[OK] Successfully unpacked {len(created_files)} files into:\n {destination}\n")
23
+
24
+ def main():
25
+ dest = sys.argv[1] if len(sys.argv) > 1 else os.getcwd()
26
+ print("\n--- Extracting Practical Files ---")
27
+ extract_files(dest)
28
+
29
+ if __name__ == "__main__":
30
+ main()
@@ -0,0 +1,53 @@
1
+ class First:
2
+ def __init__(self, graph, start, goal):
3
+ self.start = start
4
+ self.goal = goal
5
+ self.graph = graph
6
+
7
+ def bfs_shortest_path(self):
8
+
9
+ explored=[]
10
+ queue = [[self.start]]
11
+
12
+ if self.start == self.goal:
13
+ return "That Was Easy! Start = Goal"
14
+
15
+ while queue:
16
+ path = queue.pop(0)
17
+
18
+ node = path[-1]
19
+ neighbours = self.graph[node]
20
+
21
+ for neighbour in neighbours:
22
+ new_path = list(path)
23
+ new_path.append(neighbour)
24
+ queue.append(new_path)
25
+
26
+ if neighbour == self.goal:
27
+ return new_path
28
+ explored.append(node)
29
+ return "So Sorry, But A Connecting Path doenst exist:("
30
+ graph = {
31
+ "Arad": ["Zerind", "Sibiu", "Timisoara"],
32
+ "Zerind": ["Arad", "Oradea"],
33
+ "Oradea": ["Zerind", "Sibiu"],
34
+ "Sibiu": ["Arad", "Oradea", "Fagaras", "Rimnicu Vilcea"],
35
+ "Timisoara": ["Arad", "Lugoj"],
36
+ "Lugoj": ["Timisoara", "Mehadia"],
37
+ "Mehadia": ["Lugoj", "Drobeta"],
38
+ "Drobeta": ["Mehadia", "Craiova"],
39
+ "Craiova": ["Drobeta", "Rimnicu Vilcea", "Pitesti"],
40
+ "Rimnicu Vilcea": ["Sibiu", "Craiova", "Pitesti"],
41
+ "Fagaras": ["Sibiu", "Bucharest"],
42
+ "Pitesti": ["Rimnicu Vilcea", "Craiova", "Bucharest"],
43
+ "Bucharest": ["Fagaras", "Pitesti", "Giurgiu", "Urziceni"],
44
+ "Giurgiu": ["Bucharest"],
45
+ "Urziceni": ["Bucharest", "Hirsova", "Vaslui"],
46
+ "Hirsova": ["Urziceni", "Eforie"],
47
+ "Eforie": ["Hirsova"],
48
+ "Vaslui": ["Urziceni", "Iasi"],
49
+ "Iasi": ["Vaslui", "Neamt"],
50
+ "Neamt": ["Iasi"]
51
+ }
52
+ f = First(graph,"Arad","Bucharest")
53
+ print(f.bfs_shortest_path())
@@ -0,0 +1,39 @@
1
+ graph = {'Arad': ['Zerind', 'Sibiu', 'Timisoara'],
2
+ 'Bucharest': ['Urziceni','Pitesti', 'Giurgiu','Fagaras'],
3
+ 'Craiova': ['Dobreta', 'Rimnicu Vilcea', 'Pitesti'],
4
+ 'Dobreta': ['Mehadia'],
5
+ 'Eforie': ['Hirsova'],
6
+ 'Iasai': ['Vaslui','Neamt'],
7
+ 'Lugoj': ['Timisoara','Mehadia'],
8
+ 'Oradea': ['Zerind','Sibiu'],
9
+ 'Pitesti': ['Rimnicu Vilcea'],
10
+ 'Urziceni': ['Vaslui'],
11
+ 'Zerind': ['Oradea','Arad'],
12
+ 'Sibiu': ['Oradea','Arad','Rimnicu Vilcea','Fagaras'],
13
+ 'Timisoara': ['Arad','Lugoj'],
14
+ 'Mehadia': ['Lugoj','Dobreta'],
15
+ 'Rimnicu Vilcea': ['Sibiu','Pitesti','Craiova'],
16
+ 'Fagaras': ['Sibiu','Bucharest'],
17
+ 'Giurgiu': ['Bucharest'],
18
+ 'Vaslui': ['Urziceni','Iasai'],
19
+ 'Neamt': ['Iasai']}
20
+ def IDDFS(root, goal):
21
+ depth = 0
22
+ while True:
23
+ print ("Looping at depth %i " % (depth))
24
+ result = DLS(root, goal, depth)
25
+ print ("Result: %s, Goal: %s" % (result, goal))
26
+ if result == goal:
27
+ return result
28
+ depth = depth +1
29
+ def DLS(node, goal, depth):
30
+ print ("node: %s, goal %s, depth: %i" % (node, goal, depth))
31
+ if depth == 0 and node == goal:
32
+ print (" --- Found goal, returning --- ")
33
+ return node
34
+ elif depth > 0:
35
+ print ("Looping through children: %s" % (graph.get(node, [])))
36
+ for child in graph.get(node, []):
37
+ if goal == DLS(child, goal, depth-1):
38
+ return goal
39
+ IDDFS('Arad', 'Bucharest')
@@ -0,0 +1,93 @@
1
+ graph={'Arad':['Zerind','Sibiu','Timisora'],
2
+ 'Bucharest':['Urziceni','Pitesti','Giurgiu','Fagaras'],
3
+ 'Craiova':['Drobeta','Rimnicu Vilcea','Pitesti'],
4
+ 'Drobeta':['Mehadia','Craiova'],
5
+ 'Eforie':['Hirsova'],
6
+ 'Iasai':['Vaslui','Neamt'],
7
+ 'Lugoj':['Timisora','Mehadia'],
8
+ 'Oradea':['Zerind','Sibiu'],
9
+ 'Pitesti':['Rimnicu Vilcea',
10
+ 'Craiova','Bucharest'],
11
+ 'Urziceni':['Vaslui'],
12
+ 'Zerind':['Oradea','Arad'],
13
+ 'Sibiu':['Oradea','Arad','Rimnicu Vilcea','Fagaras'],
14
+ 'Timisora':['Arad','Lugoj'],
15
+ 'Mehadia':['Lugoj','Drobeta'],
16
+ 'Rimnicu Vilcea':['Sibiu','Pitesti','Craiova'],
17
+ 'Fagaras':['Sibiu','Bucharest'],
18
+ 'Giurgiu':['Bucharest'],
19
+ 'Vaslui':['Urziceni','Iasai'],
20
+ 'Neamt':['Iasai']}
21
+ pc={('Arad','Zerind'):75,
22
+ ('Arad','Timisora'):118,
23
+ ('Arad','Sibiu'):140,
24
+ ('Zerind','Oradea'):75,
25
+ ('Zerind','Arad'):75,
26
+ ('Timisora','Arad'):118,
27
+ ('Timisora','Lugoj'):111,
28
+ ('Sibiu','Arad'):140,
29
+ ('Sibiu','Fagaras'):99,
30
+ ('Sibiu','Oradea'):151,
31
+ ('Lugoj','Timisora'):111,
32
+ ('Lugoj','Mehadia'):70,
33
+ ('Rimnicu Vilcea','Sibiu'):80,
34
+ ('Sibiu','Rimnicu Vilcea'):80,
35
+ ('Rimnicu Vilcea','Pitesti'):97,
36
+ ('Rimnicu Vilcea','Craiova'):146,
37
+ ('Fagaras','Sibiu'):99,
38
+ ('Pitesti','Craiova'):138,
39
+ ('Pitesti','Bucharest'):101,
40
+ ('Craiova','Rimnicu Vilcea'):146,
41
+ ('Craiova','Drobeta'):120,
42
+ ('Craiova','Pitesti'):138,
43
+ ('Bucharest','Fagaras'):211,
44
+ ('Bucharest','Bucharest'):0,
45
+ ('Bucharest','Pitesti'):101,
46
+ ('Bucharest','Giurgiu'):90,
47
+ ('Bucharest','Urziceni'):85,
48
+ ('Giurgiu','Bucharest'):90,
49
+ ('Urziceni','Bucharest'):85,
50
+ ('Urziceni','Vaslui'):142,
51
+ ('Hirsova','Eforie'):86,
52
+ ('Vaslui','Urziceni'):142,
53
+ ('Vaslui','Iasai'):92,
54
+ ('Iasai','Vaslui'):92,
55
+ ('Iasai','Neamt'):87,
56
+ ('Neamt','Iasai'):87}
57
+ locs={'Arad':36,
58
+ 'Bucharest':0,
59
+ 'Craiova':160,
60
+ 'Drobeta':242,
61
+ 'Eforie':161,
62
+ 'Iasai':226,
63
+ 'Lugoj':244,
64
+ 'Oradea':380,
65
+ 'Pitesti':100,
66
+ 'Urziceni':80,
67
+ 'Zerind':374,
68
+ 'Sibiu':253,
69
+ 'Timisora':329,
70
+ 'Mehadia':241,
71
+ 'Rimnicu Vilcea':193,
72
+ 'Fagaras':176,
73
+ 'Giurgiu':77,
74
+ 'Vaslui':199,
75
+ 'Neamt':234,
76
+ 'Hirsova':151}
77
+
78
+ def DFS(g,v,goal,explored,path_so_far,m):
79
+ explored.add(v)
80
+ if v==goal:
81
+ return path_so_far + "->"+v
82
+ node=None
83
+ for w in g[v]:
84
+ if w not in explored:
85
+ f=locs[w]+pc[(v,w)]
86
+ if m>f:
87
+ m=f
88
+ node=w
89
+ print(m,v,w)
90
+ if node is not None:
91
+ return DFS(g,node,goal,explored,path_so_far+"->"+v,m)
92
+ return
93
+ print(DFS(graph,'Arad','Bucharest',set()," ",1000))
@@ -0,0 +1,21 @@
1
+ from sklearn.ensemble import AdaBoostClassifier
2
+ from sklearn import datasets
3
+ from sklearn.model_selection import train_test_split
4
+ from sklearn import metrics
5
+
6
+ iris = datasets.load_iris()
7
+
8
+ X = iris.data
9
+ y = iris.target
10
+
11
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) # 70% training and 30% test
12
+
13
+ abc = AdaBoostClassifier(n_estimators=50,learning_rate=1)
14
+ print(abc)
15
+
16
+ model = abc.fit(X_train, y_train)
17
+ print(model)
18
+
19
+ y_pred = model.predict(X_test)
20
+ print(model)
21
+ print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
@@ -0,0 +1,18 @@
1
+ import matplotlib.pyplot as plt
2
+ x = [4, 5, 10, 4, 3, 11, 14 , 8, 10, 12]
3
+ y = [21, 19, 24, 17, 16, 25, 24, 22, 21, 21]
4
+ classes = [0, 0, 1, 0, 0, 1, 1, 0, 1, 1]
5
+
6
+ plt.scatter(x, y, c=classes)
7
+ plt.show()
8
+
9
+ from sklearn.neighbors import KNeighborsClassifier
10
+ data = list(zip(x, y))
11
+ knn = KNeighborsClassifier(n_neighbors=1)
12
+ knn.fit(data, classes)
13
+ new_x = 8
14
+ new_y = 21
15
+ new_point = [(new_x, new_y)]
16
+ prediction = knn.predict(new_point)
17
+ plt.scatter(x + [new_x], y + [new_y], c=classes + [prediction[0]])
18
+ plt.text(x=new_x-1.7, y=new_y-0.7, s=f"new point, class: {prediction[0]}")
@@ -0,0 +1,21 @@
1
+ from sklearn.datasets import make_blobs
2
+ X, Y = make_blobs(n_samples=500, centers=2,random_state=0, cluster_std=0.40)
3
+ import matplotlib.pyplot as plt
4
+
5
+ # plotting scatters
6
+ plt.scatter(X[:, 0], X[:, 1], c=Y, s=50, cmap='spring');
7
+ plt.show()
8
+ import numpy as np
9
+ xfit = np.linspace(-1, 3.5)
10
+
11
+ # plotting scatter
12
+ plt.scatter(X[:, 0], X[:, 1], c=Y, s=50, cmap='spring')
13
+
14
+ # plot a line between the different sets of data
15
+ for m, b, d in [(1, 0.65, 0.33), (0.5, 1.6, 0.55), (-0.2, 2.9, 0.2)]:
16
+ yfit = m * xfit + b
17
+ plt.plot(xfit, yfit, '-k')
18
+ plt.fill_between(xfit, yfit - d, yfit + d, edgecolor='none',color='#AAAAAA', alpha=0.4)
19
+ plt.xlim(-1, 3.5);
20
+ plt.show()
21
+ print (X),(Y)