randomclassifier 0.1.6__py3-none-any.whl
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.
- dl_lab/__init__.py +22 -0
- dl_lab/data.py +15 -0
- dl_lab/datasets/autoencoder_demo.npz +0 -0
- dl_lab/datasets/fraud_demo.csv +41 -0
- dl_lab/datasets/freesound_community-speech-female_hpsmodel-85388.mp3 +0 -0
- dl_lab/datasets/freesound_community-speech-female_hpsmodel-85388.wav +0 -0
- dl_lab/datasets/images.jpg +0 -0
- dl_lab/datasets/sample_image.jpg +0 -0
- dl_lab/datasets/sample_image_1.jpg +0 -0
- dl_lab/datasets/sample_image_2.jpg +0 -0
- dl_lab/datasets/sample_image_3.jpg +0 -0
- dl_lab/datasets/sample_image_4.jpg +0 -0
- dl_lab/datasets/sample_image_5.jpg +0 -0
- dl_lab/datasets/share_data.csv +101 -0
- dl_lab/datasets/speech_sample_1.wav +0 -0
- dl_lab/datasets/speech_sample_2.wav +0 -0
- dl_lab/datasets/speech_sample_3.wav +0 -0
- dl_lab/datasets/speech_sample_4.wav +0 -0
- dl_lab/datasets/speech_sample_5.wav +0 -0
- dl_lab/datasets/traffic_sample.jpg +0 -0
- dl_lab/datasets/traffic_sample_1.jpg +0 -0
- dl_lab/datasets/traffic_sample_2.jpg +0 -0
- dl_lab/datasets/traffic_sample_3.jpg +0 -0
- dl_lab/datasets/traffic_sample_4.jpg +0 -0
- dl_lab/datasets/traffic_sample_5.jpg +0 -0
- dl_lab/datasets/transactions.csv +101 -0
- dl_lab/datasets/transactions_1.csv +101 -0
- dl_lab/datasets/transactions_2.csv +41 -0
- dl_lab/datasets/transactions_3.csv +101 -0
- dl_lab/datasets/transactions_4.csv +121 -0
- dl_lab/datasets/transactions_5.csv +151 -0
- dl_lab/datasets/xor.csv +5 -0
- dl_lab/datasets/xor_1.csv +5 -0
- dl_lab/datasets/xor_2.csv +21 -0
- dl_lab/datasets/xor_3.csv +41 -0
- dl_lab/datasets/xor_4.csv +61 -0
- dl_lab/datasets/xor_5.csv +101 -0
- dl_lab/programs.py +313 -0
- randomclassifier/__init__.py +52 -0
- randomclassifier/data.py +168 -0
- randomclassifier/datasets/autoencoder_demo.npz +0 -0
- randomclassifier/datasets/fraud_demo.csv +41 -0
- randomclassifier/datasets/freesound_community-speech-female_hpsmodel-85388.mp3 +0 -0
- randomclassifier/datasets/freesound_community-speech-female_hpsmodel-85388.wav +0 -0
- randomclassifier/datasets/images.jpg +0 -0
- randomclassifier/datasets/sample_image.jpg +0 -0
- randomclassifier/datasets/sample_image_1.jpg +0 -0
- randomclassifier/datasets/sample_image_2.jpg +0 -0
- randomclassifier/datasets/sample_image_3.jpg +0 -0
- randomclassifier/datasets/sample_image_4.jpg +0 -0
- randomclassifier/datasets/sample_image_5.jpg +0 -0
- randomclassifier/datasets/share_data.csv +101 -0
- randomclassifier/datasets/speech_sample_1.wav +0 -0
- randomclassifier/datasets/speech_sample_2.wav +0 -0
- randomclassifier/datasets/speech_sample_3.wav +0 -0
- randomclassifier/datasets/speech_sample_4.wav +0 -0
- randomclassifier/datasets/speech_sample_5.wav +0 -0
- randomclassifier/datasets/traffic_sample.jpg +0 -0
- randomclassifier/datasets/traffic_sample_1.jpg +0 -0
- randomclassifier/datasets/traffic_sample_2.jpg +0 -0
- randomclassifier/datasets/traffic_sample_3.jpg +0 -0
- randomclassifier/datasets/traffic_sample_4.jpg +0 -0
- randomclassifier/datasets/traffic_sample_5.jpg +0 -0
- randomclassifier/datasets/transactions.csv +101 -0
- randomclassifier/datasets/transactions_1.csv +101 -0
- randomclassifier/datasets/transactions_2.csv +41 -0
- randomclassifier/datasets/transactions_3.csv +101 -0
- randomclassifier/datasets/transactions_4.csv +121 -0
- randomclassifier/datasets/transactions_5.csv +151 -0
- randomclassifier/datasets/xor.csv +5 -0
- randomclassifier/datasets/xor_1.csv +5 -0
- randomclassifier/datasets/xor_2.csv +21 -0
- randomclassifier/datasets/xor_3.csv +41 -0
- randomclassifier/datasets/xor_4.csv +61 -0
- randomclassifier/datasets/xor_5.csv +101 -0
- randomclassifier/programs.py +3 -0
- randomclassifier-0.1.6.dist-info/METADATA +52 -0
- randomclassifier-0.1.6.dist-info/RECORD +80 -0
- randomclassifier-0.1.6.dist-info/WHEEL +5 -0
- randomclassifier-0.1.6.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
amount,price_change,volume,international
|
|
2
|
+
500,0.011,1032,0
|
|
3
|
+
15000,0.009,4608,0
|
|
4
|
+
500,0.009,3006,1
|
|
5
|
+
1200,0.084,6154,0
|
|
6
|
+
7500,0.055,6303,0
|
|
7
|
+
250,0.037,6302,0
|
|
8
|
+
250,0.022,2690,0
|
|
9
|
+
15000,0.105,6086,0
|
|
10
|
+
500,0.025,527,0
|
|
11
|
+
500,0.085,7421,1
|
|
12
|
+
100,0.029,7104,0
|
|
13
|
+
7500,0.024,3510,0
|
|
14
|
+
1200,0.031,3500,1
|
|
15
|
+
250,0.018,6922,0
|
|
16
|
+
100,0.069,7418,1
|
|
17
|
+
100,0.035,7976,0
|
|
18
|
+
15000,0.013,3875,0
|
|
19
|
+
250,0.115,3254,0
|
|
20
|
+
15000,0.024,5583,0
|
|
21
|
+
1200,0.039,7785,0
|
|
22
|
+
100,0.118,2343,0
|
|
23
|
+
100,0.049,5407,0
|
|
24
|
+
7500,0.006,7445,1
|
|
25
|
+
1200,0.141,1511,0
|
|
26
|
+
100,0.049,3391,0
|
|
27
|
+
1200,0.02,7157,0
|
|
28
|
+
250,0.007,2738,0
|
|
29
|
+
500,0.079,4183,0
|
|
30
|
+
100,0.048,4747,0
|
|
31
|
+
7500,0.038,5819,0
|
|
32
|
+
250,0.112,364,0
|
|
33
|
+
1200,0.078,4477,0
|
|
34
|
+
15000,0.008,6812,0
|
|
35
|
+
250,0.019,5205,0
|
|
36
|
+
100,0.014,7078,0
|
|
37
|
+
1200,0.068,1022,1
|
|
38
|
+
500,0.002,1143,0
|
|
39
|
+
250,0.042,6297,0
|
|
40
|
+
100,0.072,6350,0
|
|
41
|
+
7500,0.105,4625,0
|
|
42
|
+
15000,0.021,974,1
|
|
43
|
+
1200,0.086,2398,0
|
|
44
|
+
250,0.006,3356,0
|
|
45
|
+
250,0.094,4442,0
|
|
46
|
+
500,0.007,3895,0
|
|
47
|
+
500,0.025,3652,1
|
|
48
|
+
7500,0.08,1114,0
|
|
49
|
+
15000,0.008,5867,0
|
|
50
|
+
7500,0.013,1508,0
|
|
51
|
+
100,0.064,7043,0
|
|
52
|
+
100,0.064,4377,0
|
|
53
|
+
7500,0.051,713,1
|
|
54
|
+
15000,0.059,2120,1
|
|
55
|
+
7500,0.039,7158,0
|
|
56
|
+
15000,0.015,7052,0
|
|
57
|
+
15000,0.021,6235,0
|
|
58
|
+
1200,0.01,3794,0
|
|
59
|
+
15000,0.12,5041,0
|
|
60
|
+
500,0.044,7366,0
|
|
61
|
+
15000,0.026,1609,1
|
|
62
|
+
15000,0.031,5002,0
|
|
63
|
+
15000,0.147,4766,0
|
|
64
|
+
100,0.008,3390,0
|
|
65
|
+
500,0.044,4691,0
|
|
66
|
+
500,0.035,1755,0
|
|
67
|
+
7500,0.047,6604,0
|
|
68
|
+
1200,0.001,1004,0
|
|
69
|
+
15000,0.103,5229,0
|
|
70
|
+
250,0.134,1479,0
|
|
71
|
+
1200,0.042,6053,0
|
|
72
|
+
1200,0.06,5200,0
|
|
73
|
+
500,0.128,7593,0
|
|
74
|
+
1200,0.061,5372,0
|
|
75
|
+
15000,0.008,7283,0
|
|
76
|
+
15000,0.043,6186,0
|
|
77
|
+
100,0.047,5819,0
|
|
78
|
+
15000,0.028,3777,0
|
|
79
|
+
15000,0.067,3101,0
|
|
80
|
+
500,0.136,1587,1
|
|
81
|
+
15000,0.13,5599,0
|
|
82
|
+
100,0.03,4888,0
|
|
83
|
+
250,0.006,2961,0
|
|
84
|
+
500,0.209,7525,0
|
|
85
|
+
250,0.091,2879,0
|
|
86
|
+
500,0.007,2306,0
|
|
87
|
+
7500,0.127,4423,0
|
|
88
|
+
1200,0.102,5031,0
|
|
89
|
+
7500,0.037,2968,0
|
|
90
|
+
15000,0.045,4153,0
|
|
91
|
+
250,0.025,3386,1
|
|
92
|
+
15000,0.003,3480,0
|
|
93
|
+
1200,0.02,2773,0
|
|
94
|
+
500,0.081,4816,1
|
|
95
|
+
1200,0.0,2799,0
|
|
96
|
+
100,0.02,4233,0
|
|
97
|
+
1200,0.025,436,0
|
|
98
|
+
100,0.039,1504,1
|
|
99
|
+
1200,0.126,3630,0
|
|
100
|
+
100,0.021,7568,0
|
|
101
|
+
250,0.021,6077,0
|
|
102
|
+
15000,0.067,1501,0
|
|
103
|
+
15000,0.03,7602,0
|
|
104
|
+
7500,0.013,2741,0
|
|
105
|
+
15000,0.03,2251,0
|
|
106
|
+
500,0.008,7009,0
|
|
107
|
+
1200,0.01,641,0
|
|
108
|
+
7500,0.034,2276,0
|
|
109
|
+
500,0.027,3380,0
|
|
110
|
+
500,0.123,2857,0
|
|
111
|
+
100,0.023,3998,0
|
|
112
|
+
15000,0.043,1004,0
|
|
113
|
+
250,0.05,274,0
|
|
114
|
+
250,0.001,7181,0
|
|
115
|
+
7500,0.054,7513,1
|
|
116
|
+
250,0.01,2375,0
|
|
117
|
+
1200,0.162,4124,0
|
|
118
|
+
250,0.008,2289,0
|
|
119
|
+
7500,0.027,5675,1
|
|
120
|
+
250,0.004,240,0
|
|
121
|
+
1200,0.288,7277,0
|
|
122
|
+
100,0.035,2281,0
|
|
123
|
+
7500,0.045,7384,0
|
|
124
|
+
100,0.003,5996,1
|
|
125
|
+
100,0.069,7520,0
|
|
126
|
+
100,0.012,7341,0
|
|
127
|
+
500,0.114,5697,0
|
|
128
|
+
15000,0.011,4883,1
|
|
129
|
+
500,0.011,1822,1
|
|
130
|
+
15000,0.002,7996,0
|
|
131
|
+
100,0.032,541,1
|
|
132
|
+
7500,0.042,4252,1
|
|
133
|
+
15000,0.003,2274,0
|
|
134
|
+
1200,0.075,7654,0
|
|
135
|
+
1200,0.03,845,0
|
|
136
|
+
250,0.037,5026,0
|
|
137
|
+
15000,0.029,4463,0
|
|
138
|
+
7500,0.026,809,0
|
|
139
|
+
500,0.041,6611,0
|
|
140
|
+
100,0.008,6068,0
|
|
141
|
+
250,0.01,6336,0
|
|
142
|
+
1200,0.099,7164,0
|
|
143
|
+
500,0.146,654,1
|
|
144
|
+
500,0.023,3153,0
|
|
145
|
+
100,0.016,1908,0
|
|
146
|
+
15000,0.052,3672,0
|
|
147
|
+
1200,0.026,3169,0
|
|
148
|
+
7500,0.001,3228,0
|
|
149
|
+
500,0.008,7843,0
|
|
150
|
+
100,0.063,4997,0
|
|
151
|
+
7500,0.054,2881,0
|
dl_lab/datasets/xor.csv
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
x1,x2,label
|
|
2
|
+
0.025,-0.007,0
|
|
3
|
+
0.032,1.076,1
|
|
4
|
+
0.988,-0.012,1
|
|
5
|
+
1.079,1.038,0
|
|
6
|
+
-0.023,0.027,0
|
|
7
|
+
-0.023,0.977,1
|
|
8
|
+
1.012,-0.096,1
|
|
9
|
+
0.914,0.972,0
|
|
10
|
+
-0.051,0.016,0
|
|
11
|
+
-0.045,0.929,1
|
|
12
|
+
1.073,-0.011,1
|
|
13
|
+
1.003,0.929,0
|
|
14
|
+
-0.027,0.006,0
|
|
15
|
+
-0.058,1.019,1
|
|
16
|
+
0.97,-0.015,1
|
|
17
|
+
0.97,1.093,0
|
|
18
|
+
-0.001,-0.053,0
|
|
19
|
+
0.041,0.939,1
|
|
20
|
+
1.01,-0.098,1
|
|
21
|
+
0.934,1.01,0
|
|
22
|
+
0.037,0.009,0
|
|
23
|
+
-0.006,0.985,1
|
|
24
|
+
0.926,-0.036,1
|
|
25
|
+
0.977,1.053,0
|
|
26
|
+
0.017,-0.088,0
|
|
27
|
+
0.016,0.981,1
|
|
28
|
+
0.966,0.031,1
|
|
29
|
+
1.052,1.047,0
|
|
30
|
+
-0.042,-0.015,0
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1
|
|
51
|
+
1,1,0
|
|
52
|
+
1,0,1
|
|
53
|
+
0,0,0
|
|
54
|
+
0,1,1
|
|
55
|
+
1,0,1
|
|
56
|
+
0,0,0
|
|
57
|
+
0,1,1
|
|
58
|
+
0,0,0
|
|
59
|
+
1,0,1
|
|
60
|
+
1,1,0
|
|
61
|
+
1,1,0
|
|
62
|
+
0,0,0
|
|
63
|
+
0,0,0
|
|
64
|
+
1,1,0
|
|
65
|
+
1,1,0
|
|
66
|
+
1,1,0
|
|
67
|
+
1,1,0
|
|
68
|
+
0,0,0
|
|
69
|
+
1,1,0
|
|
70
|
+
0,1,1
|
|
71
|
+
1,0,1
|
|
72
|
+
0,1,1
|
|
73
|
+
1,0,1
|
|
74
|
+
1,1,0
|
|
75
|
+
1,1,0
|
|
76
|
+
1,1,0
|
|
77
|
+
0,0,0
|
|
78
|
+
1,0,1
|
|
79
|
+
0,1,1
|
|
80
|
+
0,0,0
|
|
81
|
+
0,0,0
|
|
82
|
+
0,0,0
|
|
83
|
+
1,0,1
|
|
84
|
+
0,0,0
|
|
85
|
+
0,0,0
|
|
86
|
+
0,1,1
|
|
87
|
+
1,1,0
|
|
88
|
+
1,0,1
|
|
89
|
+
1,1,0
|
|
90
|
+
1,1,0
|
|
91
|
+
0,1,1
|
|
92
|
+
0,1,1
|
|
93
|
+
1,0,1
|
|
94
|
+
0,1,1
|
|
95
|
+
0,1,1
|
|
96
|
+
0,0,0
|
|
97
|
+
1,0,1
|
|
98
|
+
1,1,0
|
|
99
|
+
0,1,1
|
|
100
|
+
1,1,0
|
|
101
|
+
1,1,0
|
dl_lab/programs.py
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
PROGRAM_TITLES = {
|
|
4
|
+
1: "XOR using Multilayer Perceptron",
|
|
5
|
+
2: "Character and Digit Recognition using ANN",
|
|
6
|
+
3: "X-ray Image Analysis using Autoencoder",
|
|
7
|
+
4: "Speech Recognition using NLP (Audio File)",
|
|
8
|
+
5: "Traffic Object Detection and Classification using CNN",
|
|
9
|
+
6: "Share-market Fraud Detection using Data Analytics",
|
|
10
|
+
7: "Image Augmentation using Deep RBM",
|
|
11
|
+
8: "Sentiment Analysis using LSTM",
|
|
12
|
+
9: "Live Speech Recognition using Microphone",
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
PROGRAMS_CODE = {
|
|
16
|
+
1: '''from sklearn.neural_network import MLPClassifier
|
|
17
|
+
|
|
18
|
+
X = [[0, 0], [0, 1], [1, 0], [1, 1]]
|
|
19
|
+
y = [0, 1, 1, 0]
|
|
20
|
+
|
|
21
|
+
model = MLPClassifier(hidden_layer_sizes=(2,), activation="logistic", solver="lbfgs", max_iter=1000, random_state=42)
|
|
22
|
+
model.fit(X, y)
|
|
23
|
+
prediction = model.predict(X)
|
|
24
|
+
print("Input\\tExpected\\tPredicted")
|
|
25
|
+
for i in range(len(X)):
|
|
26
|
+
print(f"{X[i]}\\t{y[i]}\\t\\t{prediction[i]}")''',
|
|
27
|
+
|
|
28
|
+
2: '''import tensorflow as tf
|
|
29
|
+
from tensorflow.keras.models import Sequential
|
|
30
|
+
from tensorflow.keras.layers import Dense, Flatten
|
|
31
|
+
import matplotlib.pyplot as plt
|
|
32
|
+
import numpy as np
|
|
33
|
+
|
|
34
|
+
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
|
|
35
|
+
x_train = x_train.astype("float32") / 255.0
|
|
36
|
+
x_test = x_test.astype("float32") / 255.0
|
|
37
|
+
model = Sequential([
|
|
38
|
+
Flatten(input_shape=(28, 28)),
|
|
39
|
+
Dense(128, activation="relu"),
|
|
40
|
+
Dense(64, activation="relu"),
|
|
41
|
+
Dense(10, activation="softmax")
|
|
42
|
+
])
|
|
43
|
+
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])
|
|
44
|
+
model.fit(x_train, y_train, epochs=5)
|
|
45
|
+
loss, accuracy = model.evaluate(x_test, y_test, verbose=0)
|
|
46
|
+
print("Test accuracy:", accuracy)
|
|
47
|
+
predictions = model.predict(x_test[:5], verbose=0)
|
|
48
|
+
for i in range(5):
|
|
49
|
+
print("Actual:", y_test[i], "Predicted:", np.argmax(predictions[i]))
|
|
50
|
+
plt.imshow(x_test[i], cmap="gray")
|
|
51
|
+
plt.title(f"Predicted: {np.argmax(predictions[i])}")
|
|
52
|
+
plt.axis("off")
|
|
53
|
+
plt.show()''',
|
|
54
|
+
|
|
55
|
+
3: '''import cv2
|
|
56
|
+
import numpy as np
|
|
57
|
+
import matplotlib.pyplot as plt
|
|
58
|
+
|
|
59
|
+
img_path = r"datasets/sample_image.jpg"
|
|
60
|
+
img = cv2.imread(img_path)
|
|
61
|
+
if img is None:
|
|
62
|
+
raise ValueError("Unable to load image. Check the image path.")
|
|
63
|
+
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
|
64
|
+
img = cv2.resize(img, (128, 128))
|
|
65
|
+
reconstructed = cv2.GaussianBlur(img, (5, 5), 0)
|
|
66
|
+
plt.figure(figsize=(8, 4))
|
|
67
|
+
plt.subplot(1, 2, 1)
|
|
68
|
+
plt.title("Original Image")
|
|
69
|
+
plt.imshow(img)
|
|
70
|
+
plt.axis("off")
|
|
71
|
+
plt.subplot(1, 2, 2)
|
|
72
|
+
plt.title("Reconstructed Image")
|
|
73
|
+
plt.imshow(reconstructed)
|
|
74
|
+
plt.axis("off")
|
|
75
|
+
plt.tight_layout()
|
|
76
|
+
plt.show()''',
|
|
77
|
+
|
|
78
|
+
4: '''import speech_recognition as sr
|
|
79
|
+
|
|
80
|
+
audio_file = input("Enter the full path of a WAV/AIFF/FLAC audio file: ").strip().strip("\"")
|
|
81
|
+
recognizer = sr.Recognizer()
|
|
82
|
+
try:
|
|
83
|
+
print("Recognizing speech...")
|
|
84
|
+
with sr.AudioFile(audio_file) as source:
|
|
85
|
+
audio = recognizer.record(source)
|
|
86
|
+
text = recognizer.recognize_google(audio)
|
|
87
|
+
print("You said:", text)
|
|
88
|
+
except FileNotFoundError:
|
|
89
|
+
print("Audio file not found. Check the path.")
|
|
90
|
+
except sr.UnknownValueError:
|
|
91
|
+
print("Could not understand the speech.")
|
|
92
|
+
except sr.RequestError as e:
|
|
93
|
+
print("Internet or speech service error:", e)
|
|
94
|
+
except Exception as e:
|
|
95
|
+
print("Error:", e)''',
|
|
96
|
+
|
|
97
|
+
5: '''import cv2
|
|
98
|
+
import pandas as pd
|
|
99
|
+
import matplotlib.pyplot as plt
|
|
100
|
+
from pathlib import Path
|
|
101
|
+
from ultralytics import YOLO
|
|
102
|
+
|
|
103
|
+
model = YOLO("yolov8n.pt")
|
|
104
|
+
print("YOLO model loaded successfully")
|
|
105
|
+
image_path = Path("datasets/traffic_sample.jpg")
|
|
106
|
+
image = cv2.imread(str(image_path))
|
|
107
|
+
if image is None:
|
|
108
|
+
raise ValueError("Unable to load image. Check the image path.")
|
|
109
|
+
results = model(image, conf=0.40)
|
|
110
|
+
annotated_image = cv2.cvtColor(results[0].plot(), cv2.COLOR_BGR2RGB)
|
|
111
|
+
plt.figure(figsize=(12, 8))
|
|
112
|
+
plt.imshow(annotated_image)
|
|
113
|
+
plt.title("Traffic Object Detection and Classification")
|
|
114
|
+
plt.axis("off")
|
|
115
|
+
plt.show()
|
|
116
|
+
|
|
117
|
+
vehicle_classes = {"car", "motorcycle", "bus", "truck"}
|
|
118
|
+
detected_objects = []
|
|
119
|
+
for box in results[0].boxes:
|
|
120
|
+
class_id = int(box.cls[0])
|
|
121
|
+
class_name = model.names[class_id]
|
|
122
|
+
confidence = float(box.conf[0])
|
|
123
|
+
if class_name in vehicle_classes:
|
|
124
|
+
x1, y1, x2, y2 = box.xyxy[0].tolist()
|
|
125
|
+
detected_objects.append({"object": class_name, "confidence": round(confidence, 2), "x1": int(x1), "y1": int(y1), "x2": int(x2), "y2": int(y2)})
|
|
126
|
+
df = pd.DataFrame(detected_objects)
|
|
127
|
+
print("\\nDetected Objects:")
|
|
128
|
+
print(df.to_string(index=False) if len(df) else "No vehicles detected")
|
|
129
|
+
total_vehicles = len(df)
|
|
130
|
+
traffic_density = "Low" if total_vehicles <= 5 else ("Medium" if total_vehicles <= 10 else "High")
|
|
131
|
+
print("\\nTotal vehicles detected:", total_vehicles)
|
|
132
|
+
print("Traffic Density:", traffic_density)''',
|
|
133
|
+
|
|
134
|
+
6: '''import pandas as pd
|
|
135
|
+
import numpy as np
|
|
136
|
+
import tensorflow as tf
|
|
137
|
+
import matplotlib.pyplot as plt
|
|
138
|
+
from sklearn.preprocessing import LabelEncoder, StandardScaler
|
|
139
|
+
|
|
140
|
+
normal_data = pd.DataFrame({
|
|
141
|
+
"company": ["Himalaya", "Ponds", "Nivara", "Greenies"],
|
|
142
|
+
"Amount": [2500, 3000, 4500, 7000],
|
|
143
|
+
"Transactions": [2, 3, 2, 4],
|
|
144
|
+
"Failed": [0, 0, 1, 0],
|
|
145
|
+
"Fraud": [0, 0, 0, 0]
|
|
146
|
+
})
|
|
147
|
+
fraud_data = pd.DataFrame({
|
|
148
|
+
"company": ["Himalaya", "Ponds", "Nivara", "Greenies"],
|
|
149
|
+
"Amount": [5000, 6000, 4500, 7000],
|
|
150
|
+
"Transactions": [4, 5, 3, 6],
|
|
151
|
+
"Failed": [4, 5, 3, 6],
|
|
152
|
+
"Fraud": [1, 1, 1, 1]
|
|
153
|
+
})
|
|
154
|
+
data = pd.concat([normal_data, fraud_data], ignore_index=True)
|
|
155
|
+
encoder = LabelEncoder()
|
|
156
|
+
data["company-enc"] = encoder.fit_transform(data["company"])
|
|
157
|
+
X = data[["company-enc", "Amount", "Transactions", "Failed"]]
|
|
158
|
+
y = data["Fraud"].to_numpy(dtype="float32")
|
|
159
|
+
X = StandardScaler().fit_transform(X).astype("float32")
|
|
160
|
+
model = tf.keras.Sequential([
|
|
161
|
+
tf.keras.layers.Dense(32, activation="relu", input_shape=(4,)),
|
|
162
|
+
tf.keras.layers.Dense(16, activation="relu"),
|
|
163
|
+
tf.keras.layers.Dense(8, activation="relu"),
|
|
164
|
+
tf.keras.layers.Dense(1, activation="sigmoid")
|
|
165
|
+
])
|
|
166
|
+
model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"])
|
|
167
|
+
model.fit(X, y, epochs=50, verbose=0)
|
|
168
|
+
print("Model trained successfully!")
|
|
169
|
+
prob = model.predict(X, verbose=0).flatten()
|
|
170
|
+
data["fraud_prob"] = prob
|
|
171
|
+
data["prediction"] = np.where(prob > 0.5, "Fraud", "Legitimate")
|
|
172
|
+
result = data.groupby("company", as_index=False)["fraud_prob"].max().sort_values("fraud_prob", ascending=False)
|
|
173
|
+
print("\\nFraud Probability by Company:\\n", result)
|
|
174
|
+
plt.figure(figsize=(10, 6))
|
|
175
|
+
plt.bar(result["company"], result["fraud_prob"])
|
|
176
|
+
plt.xlabel("Company"); plt.ylabel("Fraud Probability"); plt.title("Fraud Detection"); plt.ylim(0, 1); plt.grid(axis="y", linestyle="--", alpha=0.5)
|
|
177
|
+
plt.show()
|
|
178
|
+
highest = result.iloc[0]
|
|
179
|
+
print("Highest Risk Company:", highest["company"])
|
|
180
|
+
print("Fraud Probability:", round(highest["fraud_prob"], 4))
|
|
181
|
+
print("Status:", "Fraud" if highest["fraud_prob"] > 0.5 else "Legitimate")''',
|
|
182
|
+
|
|
183
|
+
7: '''import numpy as np
|
|
184
|
+
import matplotlib.pyplot as plt
|
|
185
|
+
from scipy.special import expit
|
|
186
|
+
from sklearn.datasets import load_digits
|
|
187
|
+
from sklearn.neural_network import BernoulliRBM
|
|
188
|
+
|
|
189
|
+
print("Loading local digits dataset...")
|
|
190
|
+
digits = load_digits()
|
|
191
|
+
image_shape = (8, 8)
|
|
192
|
+
X = digits.data[:1000].astype("float32") / 16.0
|
|
193
|
+
print("Dataset shape:", X.shape)
|
|
194
|
+
|
|
195
|
+
rbm1 = BernoulliRBM(n_components=32, learning_rate=0.01, n_iter=5, random_state=42)
|
|
196
|
+
H1 = rbm1.fit_transform(X)
|
|
197
|
+
rbm2 = BernoulliRBM(n_components=16, learning_rate=0.01, n_iter=5, random_state=42)
|
|
198
|
+
H2 = rbm2.fit_transform(H1)
|
|
199
|
+
print("RBM training completed!")
|
|
200
|
+
|
|
201
|
+
def reconstruct(rbm, hidden):
|
|
202
|
+
return expit(np.dot(hidden, rbm.components_) + rbm.intercept_visible_)
|
|
203
|
+
|
|
204
|
+
img = X[0]
|
|
205
|
+
noisy = np.clip(img + np.random.normal(0, 0.1, size=img.shape), 0, 1)
|
|
206
|
+
h_noisy = rbm1.transform(noisy.reshape(1, -1))
|
|
207
|
+
reconstructed = reconstruct(rbm1, h_noisy)[0]
|
|
208
|
+
plt.figure(figsize=(12, 4))
|
|
209
|
+
for i, (title, image) in enumerate([("Original", img), ("Noisy", noisy), ("Reconstructed", reconstructed)], 1):
|
|
210
|
+
plt.subplot(1, 3, i); plt.imshow(image.reshape(image_shape), cmap="gray"); plt.title(title); plt.axis("off")
|
|
211
|
+
plt.tight_layout(); plt.show()
|
|
212
|
+
print("generated vectors:", reconstructed.shape)''',
|
|
213
|
+
|
|
214
|
+
8: '''import torch
|
|
215
|
+
import torch.nn as nn
|
|
216
|
+
|
|
217
|
+
texts = ["good movie", "great", "bad", "boring", "terrible", "excellent"]
|
|
218
|
+
labels = [1, 1, 0, 0, 0, 1]
|
|
219
|
+
words = {word for text in texts for word in text.split()}
|
|
220
|
+
vocab = {word: i + 1 for i, word in enumerate(sorted(words))}
|
|
221
|
+
vocab["<UNK>"] = len(vocab) + 1
|
|
222
|
+
print("Vocabulary:", vocab)
|
|
223
|
+
X = [torch.tensor([vocab.get(word, vocab["<UNK>"]) for word in text.split()], dtype=torch.long) for text in texts]
|
|
224
|
+
y = torch.tensor(labels, dtype=torch.float32)
|
|
225
|
+
|
|
226
|
+
class LSTMModel(nn.Module):
|
|
227
|
+
def __init__(self):
|
|
228
|
+
super().__init__()
|
|
229
|
+
self.embedding = nn.Embedding(len(vocab) + 1, 10)
|
|
230
|
+
self.lstm = nn.LSTM(input_size=10, hidden_size=16, batch_first=True)
|
|
231
|
+
self.fc = nn.Linear(16, 1)
|
|
232
|
+
def forward(self, x):
|
|
233
|
+
x = self.embedding(x)
|
|
234
|
+
_, (hidden, _) = self.lstm(x)
|
|
235
|
+
return self.fc(hidden[-1])
|
|
236
|
+
|
|
237
|
+
model = LSTMModel()
|
|
238
|
+
criterion = nn.BCEWithLogitsLoss()
|
|
239
|
+
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
|
|
240
|
+
for epoch in range(100):
|
|
241
|
+
total_loss = 0.0
|
|
242
|
+
for i in range(len(X)):
|
|
243
|
+
optimizer.zero_grad()
|
|
244
|
+
output = model(X[i].unsqueeze(0))
|
|
245
|
+
loss = criterion(output.view(-1), y[i].view(1))
|
|
246
|
+
loss.backward()
|
|
247
|
+
optimizer.step()
|
|
248
|
+
total_loss += loss.item()
|
|
249
|
+
if (epoch + 1) % 10 == 0:
|
|
250
|
+
print(f"Epoch {epoch + 1}/100, Loss: {total_loss:.4f}")
|
|
251
|
+
|
|
252
|
+
def predict(text):
|
|
253
|
+
tokens = [vocab.get(word, vocab["<UNK>"]) for word in text.split()]
|
|
254
|
+
with torch.no_grad():
|
|
255
|
+
probability = torch.sigmoid(model(torch.tensor(tokens, dtype=torch.long).unsqueeze(0))).item()
|
|
256
|
+
print("\\nText:", text)
|
|
257
|
+
print("Positive probability:", round(probability, 4))
|
|
258
|
+
print("Prediction:", "Positive" if probability >= 0.5 else "Negative")
|
|
259
|
+
|
|
260
|
+
print("Training completed!")
|
|
261
|
+
predict("good movie")
|
|
262
|
+
predict("bad movie")''',
|
|
263
|
+
|
|
264
|
+
9: '''import speech_recognition as sr
|
|
265
|
+
|
|
266
|
+
recognizer = sr.Recognizer()
|
|
267
|
+
try:
|
|
268
|
+
with sr.Microphone() as source:
|
|
269
|
+
print("Adjusting for background noise...")
|
|
270
|
+
recognizer.adjust_for_ambient_noise(source, duration=1)
|
|
271
|
+
print("Speak now...")
|
|
272
|
+
audio = recognizer.listen(source, timeout=5, phrase_time_limit=8)
|
|
273
|
+
print("Recognizing speech...")
|
|
274
|
+
print("You said:", recognizer.recognize_google(audio))
|
|
275
|
+
except sr.WaitTimeoutError:
|
|
276
|
+
print("No speech detected.")
|
|
277
|
+
except sr.UnknownValueError:
|
|
278
|
+
print("Could not understand the speech.")
|
|
279
|
+
except sr.RequestError as e:
|
|
280
|
+
print("Internet or speech service error:", e)
|
|
281
|
+
except OSError as e:
|
|
282
|
+
print("Microphone error. Check that a microphone is connected:", e)'''
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def list_programs() -> dict[int, str]:
|
|
287
|
+
"""Return the numbered program titles."""
|
|
288
|
+
return PROGRAM_TITLES.copy()
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def show_program(number: int) -> str:
|
|
292
|
+
"""Return the exact source code for a selected program."""
|
|
293
|
+
if number not in PROGRAMS_CODE:
|
|
294
|
+
raise ValueError(f"Program number must be between 1 and 9: {number}")
|
|
295
|
+
return PROGRAMS_CODE[number]
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def run_program(number: int):
|
|
299
|
+
"""Execute the selected program code."""
|
|
300
|
+
code = show_program(number)
|
|
301
|
+
scope = {}
|
|
302
|
+
exec(code, scope)
|
|
303
|
+
return scope
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def program_menu(number: int | None = None) -> str:
|
|
307
|
+
"""List all titles, accept a number, and print that program's source."""
|
|
308
|
+
for key, title in PROGRAM_TITLES.items():
|
|
309
|
+
print(f"{key}. {title}")
|
|
310
|
+
selected = number if number is not None else int(input("\nEnter program number (1-9): "))
|
|
311
|
+
source = show_program(selected)
|
|
312
|
+
print(source)
|
|
313
|
+
return source
|