depd-v3 1.1.0 → 1.2.0

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.
package/astar.py ADDED
@@ -0,0 +1,93 @@
1
+ def aStarAlgo(start_node, stop_node):
2
+ open_set = set(start_node)
3
+ closed_set = set()
4
+ g = {}
5
+ parents = {}
6
+ g[start_node] = 0
7
+
8
+ parents[start_node] = start_node
9
+
10
+ while len(open_set) > 0:
11
+ n = None
12
+
13
+ for v in open_set:
14
+ if n == None or g[v] + heuristic(v) < g[n] + heuristic(n):
15
+ n = v
16
+
17
+ if n == stop_node or Graph_nodes[n] == None:
18
+ pass
19
+ else:
20
+ for (m, weight) in get_neighbors(n):
21
+ if m not in open_set and m not in closed_set:
22
+ open_set.add(m)
23
+ parents[m] = n
24
+ g[m] = g[n] + weight
25
+
26
+ else:
27
+ if g[m] > g[n] + weight:
28
+ g[m] = g[n] + weight
29
+
30
+ parents[m] = n
31
+
32
+ if m in closed_set:
33
+ closed_set.remove(m)
34
+ open_set.add(m)
35
+
36
+ if n == None:
37
+ print('Path does not exist!')
38
+ return None
39
+
40
+ if n == stop_node:
41
+ path = []
42
+
43
+ while parents[n] != n:
44
+ path.append(n)
45
+ n = parents[n]
46
+
47
+ path.append(start_node)
48
+ path.reverse()
49
+
50
+ print('Path found: {}'.format(path))
51
+ return path
52
+
53
+ open_set.remove(n)
54
+ closed_set.add(n)
55
+
56
+ print('Path does not exist!')
57
+ return None
58
+
59
+ def get_neighbors(v):
60
+ if v in Graph_nodes:
61
+ return Graph_nodes[v]
62
+ else:
63
+ return None
64
+
65
+ def heuristic(n):
66
+ H_dist = {
67
+ 'A': 11,
68
+ 'B': 6,
69
+ 'C': 5,
70
+ 'D': 7,
71
+ 'E': 3,
72
+ 'F': 6,
73
+ 'G': 5,
74
+ 'H': 3,
75
+ 'I': 1,
76
+ 'J': 0
77
+ }
78
+
79
+ return H_dist[n]
80
+
81
+ Graph_nodes = {
82
+ 'A': [('B', 6), ('F', 3)],
83
+ 'B': [('A', 6), ('C', 3), ('D', 2)],
84
+ 'C': [('B', 3), ('D', 1), ('E', 5)],
85
+ 'D': [('B', 2), ('C', 1), ('E', 8)],
86
+ 'E': [('C', 5), ('D', 8), ('I', 5), ('J', 5)],
87
+ 'F': [('A', 3), ('G', 1), ('H', 7)],
88
+ 'G': [('F', 1), ('I', 3)],
89
+ 'H': [('F', 7), ('I', 2)],
90
+ 'I': [('E', 5), ('G', 3), ('H', 2), ('J', 3)],
91
+ }
92
+
93
+ aStarAlgo('A', 'J')
package/bfs.py ADDED
@@ -0,0 +1,26 @@
1
+ graph = {
2
+ 'A': ['B', 'C'],
3
+ 'B': ['D', 'E'],
4
+ 'C': ['F'],
5
+ 'D': [],
6
+ 'E': ['F'],
7
+ 'F': []
8
+ }
9
+
10
+ visited = []
11
+ queue = []
12
+
13
+ def bfs(graph, node):
14
+ visited.append(node)
15
+ queue.append(node)
16
+
17
+ while queue:
18
+ s = queue.pop(0)
19
+ print(s, end=" ")
20
+
21
+ for neighbour in graph[s]:
22
+ if neighbour not in visited:
23
+ visited.append(neighbour)
24
+ queue.append(neighbour)
25
+
26
+ bfs(graph, 'A')
@@ -0,0 +1,22 @@
1
+ from sklearn.model_selection import train_test_split
2
+ from sklearn.tree import DecisionTreeClassifier
3
+ from sklearn.metrics import accuracy_score
4
+
5
+ import pandas as pd
6
+
7
+ sample_dataframe_df = pd.read_csv('Loan_Repay_Dataset.csv')
8
+
9
+ x = sample_dataframe_df.drop(['Result'], axis=1)
10
+ y = sample_dataframe_df['Result']
11
+
12
+ train_x, test_x, train_y, test_y = train_test_split(
13
+ x, y, test_size=0.2, random_state=100
14
+ )
15
+
16
+ estimated = DecisionTreeClassifier().fit(train_x, train_y)
17
+
18
+ predict_y = estimated.predict(test_x)
19
+
20
+ print(predict_y)
21
+
22
+ print(accuracy_score(test_y, predict_y))
package/dfs.py ADDED
@@ -0,0 +1,20 @@
1
+ graph = {
2
+ 'A': ['B', 'C'],
3
+ 'B': ['D', 'E'],
4
+ 'C': ['F'],
5
+ 'D': [],
6
+ 'E': ['F'],
7
+ 'F': []
8
+ }
9
+
10
+ visited = set()
11
+
12
+ def dfs(node):
13
+ if node not in visited:
14
+ print(node, end=" ")
15
+ visited.add(node)
16
+
17
+ for neighbour in graph[node]:
18
+ dfs(neighbour)
19
+
20
+ dfs('A')
package/knn.py ADDED
@@ -0,0 +1,28 @@
1
+ #k nearest
2
+ from sklearn.neighbors import KNeighborsClassifier
3
+ from sklearn.model_selection import train_test_split
4
+ import pandas as pd
5
+
6
+ sample_dataframe_df = pd.read_csv('Iris.csv')
7
+
8
+ sample_dataframe_df.head(5)
9
+ sample_dataframe_df['Species'].value_counts()
10
+
11
+ x = sample_dataframe_df.drop(['Id', 'Species'], axis=1)
12
+ y = sample_dataframe_df['Species']
13
+
14
+ x.head(5)
15
+ y.head(5)
16
+
17
+ train_x, test_x, train_y, test_y = train_test_split(
18
+ x,
19
+ y,
20
+ train_size=0.8,
21
+ random_state=80
22
+ )
23
+
24
+ knn = KNeighborsClassifier(n_neighbors=5)
25
+
26
+ knn.fit(train_x, train_y)
27
+
28
+ knn.score(test_x, test_y)
package/lab.ipynb CHANGED
@@ -2,7 +2,7 @@
2
2
  "cells": [
3
3
  {
4
4
  "cell_type": "code",
5
- "execution_count": 2,
5
+ "execution_count": null,
6
6
  "id": "56190fb8",
7
7
  "metadata": {},
8
8
  "outputs": [
@@ -351,7 +351,7 @@
351
351
  },
352
352
  {
353
353
  "cell_type": "code",
354
- "execution_count": 1,
354
+ "execution_count": 9,
355
355
  "id": "9a277da3",
356
356
  "metadata": {},
357
357
  "outputs": [
@@ -359,16 +359,13 @@
359
359
  "name": "stdout",
360
360
  "output_type": "stream",
361
361
  "text": [
362
- "[0 0 1 0 0 1 1 1 0 0 0 1 0 1 1 0 1 0 0 0 1 1 0 0 0 0 1 1 1 1 0 1 1 1 1 1 1\n",
362
+ "[0 0 1 0 0 1 1 1 0 0 0 1 0 1 1 0 1 0 0 0 1 1 0 0 0 0 1 1 1 1 0 0 1 1 1 1 1\n",
363
363
  " 0 0 0]\n",
364
- "0.725\n"
364
+ "0.75\n"
365
365
  ]
366
366
  }
367
367
  ],
368
368
  "source": [
369
- "import pandas as pd\n",
370
- "import numpy as np\n",
371
- "\n",
372
369
  "from sklearn.model_selection import train_test_split\n",
373
370
  "from sklearn.tree import DecisionTreeClassifier\n",
374
371
  "from sklearn.metrics import accuracy_score\n",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "depd-v3",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "",
package/pandas_lab.py ADDED
@@ -0,0 +1,26 @@
1
+ import pandas as pd
2
+
3
+ sample_dataframe_df = pd.read_csv('Iris.csv')
4
+
5
+ type(sample_dataframe_df)
6
+
7
+ sample_dataframe_df.head(5)
8
+
9
+ list(sample_dataframe_df.columns)
10
+
11
+ sample_dataframe_df.head(5).transpose()
12
+
13
+ sample_dataframe_df.shape
14
+
15
+ sample_dataframe_df[0:10]
16
+
17
+ sample_dataframe_df[-5:]
18
+
19
+ sample_dataframe_df['SepalLengthCm']
20
+
21
+ sample_dataframe_df.SepalLengthCm.value_count
22
+
23
+ sample_dataframe_df[sample_dataframe_df['PetalLengthCm']>6]
24
+
25
+ sample_dataframe_df.drop('Si.no', inplace=True, axis=1)
26
+ list(sample_dataframe_df.columns)
package/waterjug.py ADDED
@@ -0,0 +1,26 @@
1
+ #water jug bfs - use pop() for dfs
2
+ from collections import deque
3
+
4
+ def bfs(a, b, target):
5
+ q = deque([(0, 0)])
6
+ visited = set()
7
+
8
+ while q:
9
+ x, y = q.popleft()
10
+ if (x, y) in visited:
11
+ continue
12
+
13
+ visited.add((x, y))
14
+ print(x, y)
15
+
16
+ if x == target or y == target:
17
+ print("target reached")
18
+ break
19
+
20
+ q.extend([
21
+ (a, y), (x, b), (0, y), (x, 0),
22
+ (x - min(x, b - y), y + min(x, b - y)),
23
+ (x + min(y, a - x), y - min(y, a - x))
24
+ ])
25
+
26
+ bfs(4, 3, 2)