randomclassifier 0.1.0__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.
Potentially problematic release.
This version of randomclassifier might be problematic. Click here for more details.
- dl_lab/__init__.py +7 -0
- dl_lab/data.py +9 -0
- dl_lab/programs.py +144 -0
- randomclassifier/__init__.py +17 -0
- randomclassifier/programs.py +1 -0
- randomclassifier-0.1.0.dist-info/METADATA +27 -0
- randomclassifier-0.1.0.dist-info/RECORD +9 -0
- randomclassifier-0.1.0.dist-info/WHEEL +5 -0
- randomclassifier-0.1.0.dist-info/top_level.txt +2 -0
dl_lab/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""Reusable helpers for the Deep Learning Lab notebooks."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.1.0"
|
|
4
|
+
|
|
5
|
+
from .programs import PROGRAM_TITLES, list_programs, program_menu, run_program, show_program
|
|
6
|
+
|
|
7
|
+
__all__ = ["PROGRAM_TITLES", "list_programs", "program_menu", "run_program", "show_program"]
|
dl_lab/data.py
ADDED
dl_lab/programs.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import inspect
|
|
4
|
+
import textwrap
|
|
5
|
+
from typing import Callable
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
PROGRAM_TITLES = {
|
|
9
|
+
1: "XOR using Multilayer Perceptron",
|
|
10
|
+
2: "Character and Digit Recognition using ANN",
|
|
11
|
+
3: "X-ray Image Analysis using Autoencoder",
|
|
12
|
+
4: "Speech Recognition using NLP",
|
|
13
|
+
5: "Traffic Object Detection and Classification using CNN",
|
|
14
|
+
6: "Share-market Fraud Detection using Data Analytics",
|
|
15
|
+
7: "Image Augmentation using Deep RBM",
|
|
16
|
+
8: "Sentiment Analysis using LSTM",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def list_programs() -> dict[int, str]:
|
|
21
|
+
"""Return the numbered first-eight program titles."""
|
|
22
|
+
return PROGRAM_TITLES.copy()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def show_program(number: int) -> str:
|
|
26
|
+
"""Return the source code for a selected program."""
|
|
27
|
+
function = _program_function(number)
|
|
28
|
+
return textwrap.dedent(inspect.getsource(function))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def run_program(number: int):
|
|
32
|
+
"""Execute a selected program and return its result."""
|
|
33
|
+
return _program_function(number)()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def program_menu(number: int | None = None) -> str:
|
|
37
|
+
"""List all titles, accept a number, and print that program's source."""
|
|
38
|
+
for key, title in PROGRAM_TITLES.items():
|
|
39
|
+
print(f"{key}. {title}")
|
|
40
|
+
selected = number if number is not None else int(input("Enter program number: "))
|
|
41
|
+
source = show_program(selected)
|
|
42
|
+
print(source)
|
|
43
|
+
return source
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _program_function(number: int) -> Callable:
|
|
47
|
+
functions = {
|
|
48
|
+
1: xor_mlp,
|
|
49
|
+
2: mnist_ann,
|
|
50
|
+
3: xray_autoencoder,
|
|
51
|
+
4: speech_recognition_nlp,
|
|
52
|
+
5: traffic_cnn,
|
|
53
|
+
6: fraud_detection,
|
|
54
|
+
7: rbm_augmentation,
|
|
55
|
+
8: lstm_sentiment,
|
|
56
|
+
}
|
|
57
|
+
if number not in functions:
|
|
58
|
+
raise ValueError(f"Program number must be between 1 and 8: {number}")
|
|
59
|
+
return functions[number]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def xor_mlp():
|
|
63
|
+
import numpy as np
|
|
64
|
+
from sklearn.neural_network import MLPClassifier
|
|
65
|
+
x=np.array([[0,0],[0,1],[1,0],[1,1]])
|
|
66
|
+
y=[0,1,1,0]
|
|
67
|
+
model=MLPClassifier(hidden_layer_sizes=(4,),activation="tanh",solver="lbfgs",max_iter=2000,random_state=1).fit(x,y)
|
|
68
|
+
return model.predict(x)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def mnist_ann():
|
|
72
|
+
import tensorflow as tf
|
|
73
|
+
(x,y),(test_x,test_y)=tf.keras.datasets.mnist.load_data()
|
|
74
|
+
model=tf.keras.Sequential([tf.keras.layers.Flatten(input_shape=(28,28)),tf.keras.layers.Dense(128,activation="relu"),tf.keras.layers.Dense(10,activation="softmax")])
|
|
75
|
+
model.compile("adam","sparse_categorical_crossentropy",metrics=["accuracy"])
|
|
76
|
+
model.fit(x/255.0,y,epochs=3)
|
|
77
|
+
return model.evaluate(test_x/255.0,test_y,verbose=0)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def xray_autoencoder():
|
|
81
|
+
import tensorflow as tf
|
|
82
|
+
from tensorflow.keras import layers as L
|
|
83
|
+
from pathlib import Path
|
|
84
|
+
import numpy as np
|
|
85
|
+
local=Path("datasets/autoencoder_demo.npz")
|
|
86
|
+
if local.exists():
|
|
87
|
+
images=np.load(local)["images"].astype("float32")
|
|
88
|
+
else:
|
|
89
|
+
images=tf.random.uniform((256,64,64,1))
|
|
90
|
+
data=tf.data.Dataset.from_tensor_slices(images).batch(16)
|
|
91
|
+
inputs=L.Input((64,64,1))
|
|
92
|
+
hidden=L.Conv2D(16,3,2,"same",activation="relu")(inputs)
|
|
93
|
+
hidden=L.Conv2D(8,3,2,"same",activation="relu")(hidden)
|
|
94
|
+
output=L.Conv2DTranspose(16,3,2,"same",activation="relu")(hidden)
|
|
95
|
+
output=L.Conv2DTranspose(1,3,2,"same",activation="sigmoid")(output)
|
|
96
|
+
model=tf.keras.Model(inputs,output)
|
|
97
|
+
model.compile("adam","mse")
|
|
98
|
+
return model.fit(data,epochs=3)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def speech_recognition_nlp():
|
|
102
|
+
import speech_recognition as sr
|
|
103
|
+
recognizer=sr.Recognizer()
|
|
104
|
+
with sr.Microphone() as source:
|
|
105
|
+
audio=recognizer.listen(source,timeout=5,phrase_time_limit=10)
|
|
106
|
+
return recognizer.recognize_google(audio)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def traffic_cnn():
|
|
110
|
+
import cv2
|
|
111
|
+
model=cv2.dnn.readNetFromTensorflow("frozen_inference_graph.pb","graph.pbtxt")
|
|
112
|
+
image=cv2.imread("traffic.jpg")
|
|
113
|
+
height,width=image.shape[:2]
|
|
114
|
+
model.setInput(cv2.dnn.blobFromImage(image,size=(300,300),swapRB=True))
|
|
115
|
+
detections=model.forward()
|
|
116
|
+
return [(int(d[1]),(d[3:7]*[width,height,width,height]).astype(int).tolist()) for d in detections[0,0] if d[2]>.5]
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def fraud_detection():
|
|
120
|
+
import pandas as pd
|
|
121
|
+
from sklearn.ensemble import IsolationForest
|
|
122
|
+
data=pd.read_csv("datasets/transactions.csv")
|
|
123
|
+
data["fraud_flag"]=IsolationForest(contamination=.02,random_state=1).fit_predict(data.select_dtypes("number"))==-1
|
|
124
|
+
return data[data.fraud_flag]
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def rbm_augmentation():
|
|
128
|
+
from sklearn.neural_network import BernoulliRBM
|
|
129
|
+
from sklearn.datasets import load_digits
|
|
130
|
+
x=load_digits().data/16.0
|
|
131
|
+
model=BernoulliRBM(n_components=64,learning_rate=.05,n_iter=20,random_state=1).fit(x)
|
|
132
|
+
return model.transform(x)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def lstm_sentiment():
|
|
136
|
+
import tensorflow as tf
|
|
137
|
+
from tensorflow.keras import layers as L
|
|
138
|
+
(x,y),(test_x,test_y)=tf.keras.datasets.imdb.load_data(num_words=10000)
|
|
139
|
+
pad=tf.keras.preprocessing.sequence.pad_sequences
|
|
140
|
+
x=pad(x,maxlen=200); test_x=pad(test_x,maxlen=200)
|
|
141
|
+
model=tf.keras.Sequential([L.Embedding(10000,32),L.LSTM(32),L.Dense(1,activation="sigmoid")])
|
|
142
|
+
model.compile("adam","binary_crossentropy",metrics=["accuracy"])
|
|
143
|
+
model.fit(x,y,epochs=2)
|
|
144
|
+
return model.evaluate(test_x,test_y,verbose=0)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from dl_lab.programs import PROGRAM_TITLES, show_program
|
|
2
|
+
|
|
3
|
+
__version__ = "0.1.0"
|
|
4
|
+
|
|
5
|
+
def models():
|
|
6
|
+
for number, title in PROGRAM_TITLES.items():
|
|
7
|
+
print(f"{number}. {title}")
|
|
8
|
+
return PROGRAM_TITLES.copy()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def model(number: int):
|
|
12
|
+
source = show_program(number)
|
|
13
|
+
print(source)
|
|
14
|
+
return source
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
__all__ = ["models", "model"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from dl_lab.programs import *
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: randomclassifier
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Deep learning laboratory programs and reusable classifiers
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: numpy>=1.24
|
|
8
|
+
Requires-Dist: pandas>=2.0
|
|
9
|
+
Requires-Dist: scikit-learn>=1.3
|
|
10
|
+
Requires-Dist: tensorflow>=2.13
|
|
11
|
+
Requires-Dist: jupyter>=1.0
|
|
12
|
+
Requires-Dist: matplotlib>=3.7
|
|
13
|
+
|
|
14
|
+
# DL Lab PIP Project
|
|
15
|
+
|
|
16
|
+
This folder contains the installable Python project for the Deep Learning Lab notebooks.
|
|
17
|
+
|
|
18
|
+
The package is named `randomclassifier` and exposes exactly two public functions:
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from randomclassifier import models, model
|
|
22
|
+
|
|
23
|
+
models()
|
|
24
|
+
model(1)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Notebook files and datasets remain in the parent `DL_LAB` folder.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
dl_lab/__init__.py,sha256=5gidVLhusHTOpmOQgb3gqeEyVW9briPvAO2F4DfO-x4,271
|
|
2
|
+
dl_lab/data.py,sha256=yzfMZ7Y0EmhLDwN5V1lox8echC3kkdAqYOgPVng3IBA,187
|
|
3
|
+
dl_lab/programs.py,sha256=4ulgJRIisiI5IeSEKshKlah-cYYXjTuIHLlkdPyq468,5078
|
|
4
|
+
randomclassifier/__init__.py,sha256=_zPVsWKpdOJD-9n-E95XNzCfEcwaUPZcw_ElE-Nrcd4,341
|
|
5
|
+
randomclassifier/programs.py,sha256=TTE9hOol7MBySKDn7Xgrs0KXZIygOIflBU1wfllVLuc,30
|
|
6
|
+
randomclassifier-0.1.0.dist-info/METADATA,sha256=ecovMHSxvNwFfDQcOdsZ_vAj3Q0W34GEcTe5fDbqOgM,709
|
|
7
|
+
randomclassifier-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
8
|
+
randomclassifier-0.1.0.dist-info/top_level.txt,sha256=v4cH57UFW0U9YN4i9uEDKeXvIVNFb6NyHxXULVnfBQA,24
|
|
9
|
+
randomclassifier-0.1.0.dist-info/RECORD,,
|