expml 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.
- expml-0.1.0/PKG-INFO +46 -0
- expml-0.1.0/README.md +39 -0
- expml-0.1.0/pyproject.toml +14 -0
- expml-0.1.0/pyproject.toml.orig +14 -0
- expml-0.1.0/src/expml/__init__.py +28 -0
- expml-0.1.0/src/expml/auth.py +35 -0
- expml-0.1.0/src/expml/progs.py +228 -0
expml-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: expml
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Requires-Python: >=3.13
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
|
|
8
|
+
# expml
|
|
9
|
+
|
|
10
|
+
A Python package for quick access and reference to standard Machine Learning experiment codes.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **Password Protection**: Authenticate before accessing experiment blocks.
|
|
15
|
+
- **Listing Function**: View available machine learning programs.
|
|
16
|
+
- **Get Snippets**: Retrieve code blocks programmatically as strings using program indices.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install expml
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### In Python Scripts / Notebooks:
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import expml
|
|
30
|
+
|
|
31
|
+
# 1. Authenticate (Password: banana)
|
|
32
|
+
expml.login("banana")
|
|
33
|
+
|
|
34
|
+
# 2. List all available programs
|
|
35
|
+
expml.list() # or expml.list_progs()
|
|
36
|
+
|
|
37
|
+
# 3. Retrieve code block by index
|
|
38
|
+
code_text = expml.get(1)
|
|
39
|
+
print(code_text)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Command Line Interface (CLI):
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
expml
|
|
46
|
+
```
|
expml-0.1.0/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# expml
|
|
2
|
+
|
|
3
|
+
A Python package for quick access and reference to standard Machine Learning experiment codes.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Password Protection**: Authenticate before accessing experiment blocks.
|
|
8
|
+
- **Listing Function**: View available machine learning programs.
|
|
9
|
+
- **Get Snippets**: Retrieve code blocks programmatically as strings using program indices.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install expml
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### In Python Scripts / Notebooks:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import expml
|
|
23
|
+
|
|
24
|
+
# 1. Authenticate (Password: banana)
|
|
25
|
+
expml.login("banana")
|
|
26
|
+
|
|
27
|
+
# 2. List all available programs
|
|
28
|
+
expml.list() # or expml.list_progs()
|
|
29
|
+
|
|
30
|
+
# 3. Retrieve code block by index
|
|
31
|
+
code_text = expml.get(1)
|
|
32
|
+
print(code_text)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Command Line Interface (CLI):
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
expml
|
|
39
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "expml"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.13"
|
|
7
|
+
dependencies = []
|
|
8
|
+
|
|
9
|
+
[project.scripts]
|
|
10
|
+
expml = "expml:main"
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["uv_build>=0.13.6,<0.14.0"]
|
|
14
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "expml"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.13"
|
|
7
|
+
dependencies = []
|
|
8
|
+
|
|
9
|
+
[project.scripts]
|
|
10
|
+
expml = "expml:main"
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["uv_build>=0.13.6,<0.14.0"]
|
|
14
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""expml: Machine Learning Experiments Package."""
|
|
2
|
+
|
|
3
|
+
from .auth import login, is_authenticated
|
|
4
|
+
from .progs import list_progs, get, code, PROGRAMS
|
|
5
|
+
|
|
6
|
+
# Provide an alias 'list' if imported as 'from expml import list' or expml.list()
|
|
7
|
+
list = list_progs
|
|
8
|
+
|
|
9
|
+
__all__ = ["login", "is_authenticated", "list_progs", "list", "get", "code", "PROGRAMS"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
"""CLI entrypoint."""
|
|
14
|
+
import sys
|
|
15
|
+
print("Welcome to expml!")
|
|
16
|
+
if not login():
|
|
17
|
+
sys.exit(1)
|
|
18
|
+
|
|
19
|
+
list_progs()
|
|
20
|
+
try:
|
|
21
|
+
choice = input("Enter program number to view (or 'q' to quit): ").strip()
|
|
22
|
+
if choice.lower() != 'q' and choice.isdigit():
|
|
23
|
+
idx = int(choice)
|
|
24
|
+
print("\n" + "=" * 50)
|
|
25
|
+
print(get(idx))
|
|
26
|
+
print("=" * 50)
|
|
27
|
+
except KeyboardInterrupt:
|
|
28
|
+
print("\nExiting.")
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Authentication module for expml."""
|
|
2
|
+
|
|
3
|
+
_authenticated = False
|
|
4
|
+
_PASSWORD = "banana"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def login(password: str | None = None) -> bool:
|
|
8
|
+
"""Authenticate to unlock access to programs.
|
|
9
|
+
|
|
10
|
+
If password is not passed, prompts user securely via getpass.
|
|
11
|
+
"""
|
|
12
|
+
global _authenticated
|
|
13
|
+
if password is None:
|
|
14
|
+
import getpass
|
|
15
|
+
password = getpass.getpass("Enter password: ")
|
|
16
|
+
|
|
17
|
+
if password == _PASSWORD:
|
|
18
|
+
_authenticated = True
|
|
19
|
+
print("Login successful.")
|
|
20
|
+
return True
|
|
21
|
+
else:
|
|
22
|
+
_authenticated = False
|
|
23
|
+
print("Incorrect password.")
|
|
24
|
+
return False
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def is_authenticated() -> bool:
|
|
28
|
+
"""Return True if currently authenticated."""
|
|
29
|
+
return _authenticated
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def require_auth() -> None:
|
|
33
|
+
"""Raise PermissionError or prompt login if not authenticated."""
|
|
34
|
+
if not is_authenticated():
|
|
35
|
+
raise PermissionError("Access denied. Please call login('password') first.")
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"""Programs catalogue and retrieval module."""
|
|
2
|
+
|
|
3
|
+
from .auth import is_authenticated, require_auth
|
|
4
|
+
|
|
5
|
+
PROGRAMS = {
|
|
6
|
+
1: {
|
|
7
|
+
"title": "Linear Regression",
|
|
8
|
+
"description": "Simple Linear Regression using Scikit-Learn & SciPy linregress",
|
|
9
|
+
"code": '''import numpy as np
|
|
10
|
+
from sklearn.linear_model import LinearRegression
|
|
11
|
+
from sklearn.metrics import r2_score
|
|
12
|
+
|
|
13
|
+
# Dataset
|
|
14
|
+
X = np.array([[500], [600], [700], [800], [900],
|
|
15
|
+
[1000], [1100], [1200], [1300], [1400]])
|
|
16
|
+
|
|
17
|
+
y = np.array([20, 25, 30, 35, 40, 45, 50, 55, 60, 65])
|
|
18
|
+
|
|
19
|
+
# Create model
|
|
20
|
+
model = LinearRegression()
|
|
21
|
+
|
|
22
|
+
# Train model
|
|
23
|
+
model.fit(X, y)
|
|
24
|
+
|
|
25
|
+
# Predict
|
|
26
|
+
pred = model.predict(X)
|
|
27
|
+
|
|
28
|
+
# Display results
|
|
29
|
+
print("Predicted prices:", pred)
|
|
30
|
+
print("R2 Score:", r2_score(y, pred))
|
|
31
|
+
|
|
32
|
+
# Predict price for a new house
|
|
33
|
+
print("Price:", model.predict([[1500]]))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# Using linregress
|
|
37
|
+
from scipy.stats import linregress
|
|
38
|
+
|
|
39
|
+
# Step 1: Create dataset
|
|
40
|
+
x = np.array([500, 600, 700, 800, 900,
|
|
41
|
+
1000, 1100, 1200, 1300, 1400])
|
|
42
|
+
|
|
43
|
+
y = np.array([20, 25, 30, 35, 40,
|
|
44
|
+
45, 50, 55, 60, 65])
|
|
45
|
+
|
|
46
|
+
# Step 2: Apply Linear Regression
|
|
47
|
+
slope, intercept, r, p, se = linregress(x, y)
|
|
48
|
+
|
|
49
|
+
# Step 3: Predict values
|
|
50
|
+
pred = slope * x + intercept
|
|
51
|
+
|
|
52
|
+
# Step 4: Display results
|
|
53
|
+
print("Slope:", slope)
|
|
54
|
+
print("Intercept:", intercept)
|
|
55
|
+
print("Predicted Prices:", pred)
|
|
56
|
+
print("R2 Score:", r**2)
|
|
57
|
+
|
|
58
|
+
# Step 5: Predict a new house price
|
|
59
|
+
area = 1500
|
|
60
|
+
price = slope * area + intercept
|
|
61
|
+
|
|
62
|
+
print("Predicted Price:", price)
|
|
63
|
+
'''
|
|
64
|
+
},
|
|
65
|
+
2: {
|
|
66
|
+
"title": "Logistic Regression",
|
|
67
|
+
"description": "Binary classification using Logistic Regression",
|
|
68
|
+
"code": '''import numpy as np
|
|
69
|
+
from sklearn.linear_model import LogisticRegression
|
|
70
|
+
from sklearn.metrics import accuracy_score
|
|
71
|
+
|
|
72
|
+
# Dataset
|
|
73
|
+
X = np.array([[1], [2], [3], [4], [5],
|
|
74
|
+
[6], [7], [8], [9], [10]])
|
|
75
|
+
|
|
76
|
+
y = np.array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1])
|
|
77
|
+
|
|
78
|
+
# Create model
|
|
79
|
+
model = LogisticRegression()
|
|
80
|
+
|
|
81
|
+
# Train model
|
|
82
|
+
model.fit(X, y)
|
|
83
|
+
|
|
84
|
+
# Predict
|
|
85
|
+
pred = model.predict(X)
|
|
86
|
+
|
|
87
|
+
# Display results
|
|
88
|
+
print("Predictions:", pred)
|
|
89
|
+
print("Accuracy:", accuracy_score(y, pred))
|
|
90
|
+
|
|
91
|
+
# Predict for a new student
|
|
92
|
+
print("Result:", model.predict([[7]]))
|
|
93
|
+
'''
|
|
94
|
+
},
|
|
95
|
+
3: {
|
|
96
|
+
"title": "AdaBoost Classifier",
|
|
97
|
+
"description": "Boosting classification using AdaBoostClassifier",
|
|
98
|
+
"code": '''import numpy as np
|
|
99
|
+
from sklearn.ensemble import AdaBoostClassifier
|
|
100
|
+
from sklearn.metrics import accuracy_score
|
|
101
|
+
|
|
102
|
+
# Dataset: Study hours, Attendance
|
|
103
|
+
X = np.array([
|
|
104
|
+
[1, 40], [2, 45], [3, 50], [4, 55], [5, 60],
|
|
105
|
+
[6, 65], [7, 70], [8, 75], [9, 85], [10, 90]
|
|
106
|
+
])
|
|
107
|
+
|
|
108
|
+
# 0 = Fail, 1 = Pass
|
|
109
|
+
y = np.array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1])
|
|
110
|
+
|
|
111
|
+
# Create model
|
|
112
|
+
model = AdaBoostClassifier(n_estimators=10, random_state=42)
|
|
113
|
+
|
|
114
|
+
# Train model
|
|
115
|
+
model.fit(X, y)
|
|
116
|
+
|
|
117
|
+
# Predict
|
|
118
|
+
pred = model.predict(X)
|
|
119
|
+
|
|
120
|
+
# Display results
|
|
121
|
+
print("Predictions:", pred)
|
|
122
|
+
print("Accuracy:", accuracy_score(y, pred))
|
|
123
|
+
|
|
124
|
+
# Predict for new student
|
|
125
|
+
print("Result:", model.predict([[7, 75]]))
|
|
126
|
+
'''
|
|
127
|
+
},
|
|
128
|
+
4: {
|
|
129
|
+
"title": "Multiple Linear Regression (MLR)",
|
|
130
|
+
"description": "Multi-feature regression using LinearRegression",
|
|
131
|
+
"code": '''import numpy as np
|
|
132
|
+
from sklearn.linear_model import LinearRegression
|
|
133
|
+
from sklearn.metrics import r2_score
|
|
134
|
+
|
|
135
|
+
# Dataset: Area, Bedrooms, Age
|
|
136
|
+
X = np.array([
|
|
137
|
+
[500, 1, 10], [600, 2, 8], [700, 2, 7],
|
|
138
|
+
[800, 2, 5], [900, 3, 6], [1000, 3, 4],
|
|
139
|
+
[1100, 3, 3], [1200, 4, 4], [1300, 4, 2],
|
|
140
|
+
[1400, 4, 1]
|
|
141
|
+
])
|
|
142
|
+
|
|
143
|
+
# House prices in lakhs
|
|
144
|
+
y = np.array([20, 25, 30, 35, 40, 45, 50, 55, 60, 65])
|
|
145
|
+
|
|
146
|
+
# Create model
|
|
147
|
+
model = LinearRegression()
|
|
148
|
+
|
|
149
|
+
# Train model
|
|
150
|
+
model.fit(X, y)
|
|
151
|
+
|
|
152
|
+
# Predict
|
|
153
|
+
pred = model.predict(X)
|
|
154
|
+
|
|
155
|
+
# Display results
|
|
156
|
+
print("Predictions:", pred)
|
|
157
|
+
print("R2 Score:", r2_score(y, pred))
|
|
158
|
+
|
|
159
|
+
# Predict for new house
|
|
160
|
+
print("Price:", model.predict([[1500, 4, 2]]))
|
|
161
|
+
'''
|
|
162
|
+
},
|
|
163
|
+
5: {
|
|
164
|
+
"title": "Support Vector Machine (SVM)",
|
|
165
|
+
"description": "Classification with standard scaling and SVC",
|
|
166
|
+
"code": '''import numpy as np
|
|
167
|
+
from sklearn.svm import SVC
|
|
168
|
+
from sklearn.metrics import accuracy_score
|
|
169
|
+
from sklearn.preprocessing import StandardScaler
|
|
170
|
+
|
|
171
|
+
# Dataset: Study hours, Attendance
|
|
172
|
+
X = np.array([
|
|
173
|
+
[1, 40], [2, 45], [3, 50], [4, 55], [5, 60],
|
|
174
|
+
[6, 65], [7, 70], [8, 75], [9, 85], [10, 90]
|
|
175
|
+
])
|
|
176
|
+
|
|
177
|
+
# 0 = Fail, 1 = Pass
|
|
178
|
+
y = np.array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1])
|
|
179
|
+
|
|
180
|
+
# Feature scaling
|
|
181
|
+
scaler = StandardScaler()
|
|
182
|
+
X = scaler.fit_transform(X)
|
|
183
|
+
|
|
184
|
+
# Create model
|
|
185
|
+
model = SVC(kernel='linear')
|
|
186
|
+
|
|
187
|
+
# Train model
|
|
188
|
+
model.fit(X, y)
|
|
189
|
+
|
|
190
|
+
# Predict
|
|
191
|
+
pred = model.predict(X)
|
|
192
|
+
|
|
193
|
+
# Display results
|
|
194
|
+
print("Predictions:", pred)
|
|
195
|
+
print("Accuracy:", accuracy_score(y, pred))
|
|
196
|
+
|
|
197
|
+
# Predict for new student
|
|
198
|
+
new_student = scaler.transform([[7, 75]])
|
|
199
|
+
print("Result:", model.predict(new_student))
|
|
200
|
+
'''
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def list_progs() -> None:
|
|
206
|
+
"""List all available ML programs with index numbers."""
|
|
207
|
+
require_auth()
|
|
208
|
+
print("\n--- Available ML Programs ---")
|
|
209
|
+
for idx, item in PROGRAMS.items():
|
|
210
|
+
print(f"[{idx}] {item['title']} - {item['description']}")
|
|
211
|
+
print("-----------------------------\n")
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def get(index: int) -> str:
|
|
215
|
+
"""Return the code string for the program at the specified index."""
|
|
216
|
+
require_auth()
|
|
217
|
+
if index in PROGRAMS:
|
|
218
|
+
return PROGRAMS[index]["code"]
|
|
219
|
+
raise IndexError(f"Program index {index} not found. Available indexes: {list(PROGRAMS.keys())}")
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def code(choice: int) -> None:
|
|
223
|
+
"""Print the program code (for backward compatibility)."""
|
|
224
|
+
try:
|
|
225
|
+
content = get(choice)
|
|
226
|
+
print(content)
|
|
227
|
+
except Exception as e:
|
|
228
|
+
print(e)
|