sklearn-kit 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.
@@ -0,0 +1 @@
1
+ from .model import fit_predict
sklearn_kit/model.py ADDED
@@ -0,0 +1,11 @@
1
+ from pathlib import Path
2
+ import shutil
3
+
4
+ def fit_predict(problem):
5
+ problem = problem.lower().strip()
6
+ if problem not in {"weather", "air_quality"}:
7
+ raise ValueError("Use 'weather' or 'air_quality'")
8
+
9
+ folder = Path(__file__).parent / "templates" / problem
10
+ for name in ("server.py", "client.py", "train.py"):
11
+ shutil.copyfile(folder / name, Path(name))
@@ -0,0 +1,24 @@
1
+ import asyncio
2
+ import json
3
+ import joblib
4
+ from aiocoap import Context, Message, GET
5
+
6
+ async def main():
7
+ protocol = await Context.create_client_context()
8
+ request = Message(code=GET, uri="coap://127.0.0.1:5683/air")
9
+ response = await protocol.request(request).response
10
+ data = json.loads(response.payload.decode())
11
+
12
+ for key, value in data.items():
13
+ print(key, ":", value)
14
+
15
+ try:
16
+ model = joblib.load("model.pkl")
17
+ x = [[data["PM2.5"], data["PM10"], data["NO2"],
18
+ data["SO2"], data["O3"]]]
19
+ print("Prediction:", model.predict(x)[0])
20
+ except FileNotFoundError:
21
+ print("Run train.py first.")
22
+
23
+ if __name__ == "__main__":
24
+ asyncio.run(main())
@@ -0,0 +1,31 @@
1
+ import asyncio
2
+ import json
3
+ import requests
4
+ from aiocoap import Context, Message
5
+ from aiocoap.resource import Resource, Site
6
+
7
+ URL = ("https://air-quality-api.open-meteo.com/v1/air-quality"
8
+ "?latitude=9.93&longitude=76.27"
9
+ "&current=pm2_5,pm10,nitrogen_dioxide,sulphur_dioxide,ozone")
10
+
11
+ class Air(Resource):
12
+ async def render_get(self, request):
13
+ current = requests.get(URL).json()["current"]
14
+ data = {
15
+ "PM2.5": current["pm2_5"],
16
+ "PM10": current["pm10"],
17
+ "NO2": current["nitrogen_dioxide"],
18
+ "SO2": current["sulphur_dioxide"],
19
+ "O3": current["ozone"]
20
+ }
21
+ return Message(payload=json.dumps(data).encode())
22
+
23
+ async def main():
24
+ root = Site()
25
+ root.add_resource(["air"], Air())
26
+ await Context.create_server_context(root, bind=("127.0.0.1", 5683))
27
+ print("Air Quality CoAP server running...")
28
+ await asyncio.get_running_loop().create_future()
29
+
30
+ if __name__ == "__main__":
31
+ asyncio.run(main())
@@ -0,0 +1,25 @@
1
+ import pandas as pd
2
+ import joblib
3
+ from sklearn.model_selection import train_test_split
4
+ from sklearn.ensemble import RandomForestClassifier
5
+ from sklearn.metrics import accuracy_score
6
+
7
+ df = pd.read_csv("city_day.csv")
8
+
9
+ features = ["PM2.5", "PM10", "NO2", "SO2", "O3"]
10
+ target = "AQI_Bucket"
11
+
12
+ df = df.dropna(subset=features + [target])
13
+ X = df[features]
14
+ y = df[target]
15
+
16
+ X_train, X_test, y_train, y_test = train_test_split(
17
+ X, y, test_size=0.2, random_state=42
18
+ )
19
+
20
+ model = RandomForestClassifier(n_estimators=100, random_state=42)
21
+ model.fit(X_train, y_train)
22
+
23
+ print("Accuracy:", accuracy_score(y_test, model.predict(X_test)))
24
+ joblib.dump(model, "model.pkl")
25
+ print("Model saved as model.pkl")
@@ -0,0 +1,25 @@
1
+ import asyncio
2
+ import json
3
+ import joblib
4
+ from aiocoap import Context, Message, GET
5
+
6
+ async def main():
7
+ protocol = await Context.create_client_context()
8
+ request = Message(code=GET, uri="coap://127.0.0.1:5683/weather")
9
+ response = await protocol.request(request).response
10
+ data = json.loads(response.payload.decode())
11
+
12
+ for key, value in data.items():
13
+ print(key, ":", value)
14
+
15
+ try:
16
+ model = joblib.load("model.pkl")
17
+ x = [[data["temperature"], data["humidity"], data["precipitation"],
18
+ data["cloud_cover"], data["wind_speed"],
19
+ data["surface_pressure"]]]
20
+ print("Prediction:", model.predict(x)[0])
21
+ except FileNotFoundError:
22
+ print("Run train.py first.")
23
+
24
+ if __name__ == "__main__":
25
+ asyncio.run(main())
@@ -0,0 +1,33 @@
1
+ import asyncio
2
+ import json
3
+ import requests
4
+ from aiocoap import Context, Message
5
+ from aiocoap.resource import Resource, Site
6
+
7
+ URL = ("https://api.open-meteo.com/v1/forecast"
8
+ "?latitude=9.93&longitude=76.27"
9
+ "&current=temperature_2m,relative_humidity_2m,precipitation,"
10
+ "cloud_cover,wind_speed_10m,surface_pressure")
11
+
12
+ class Weather(Resource):
13
+ async def render_get(self, request):
14
+ current = requests.get(URL).json()["current"]
15
+ data = {
16
+ "temperature": current["temperature_2m"],
17
+ "humidity": current["relative_humidity_2m"],
18
+ "precipitation": current["precipitation"],
19
+ "cloud_cover": current["cloud_cover"],
20
+ "wind_speed": current["wind_speed_10m"],
21
+ "surface_pressure": current["surface_pressure"]
22
+ }
23
+ return Message(payload=json.dumps(data).encode())
24
+
25
+ async def main():
26
+ root = Site()
27
+ root.add_resource(["weather"], Weather())
28
+ await Context.create_server_context(root, bind=("127.0.0.1", 5683))
29
+ print("Weather CoAP server running...")
30
+ await asyncio.get_running_loop().create_future()
31
+
32
+ if __name__ == "__main__":
33
+ asyncio.run(main())
@@ -0,0 +1,39 @@
1
+ import pandas as pd
2
+ import joblib
3
+ from sklearn.model_selection import train_test_split
4
+ from sklearn.tree import DecisionTreeClassifier
5
+ from sklearn.metrics import accuracy_score
6
+
7
+ def weather_class(code):
8
+ if code in [0, 1]: return "Clear"
9
+ if code in [2, 3]: return "Cloudy"
10
+ if code in [51, 53, 55]: return "Drizzle"
11
+ if code in [61, 63, 65]: return "Rain"
12
+ return "Other"
13
+
14
+ df = pd.read_csv("weather.csv")
15
+ df.rename(columns={
16
+ "temperature_2m": "temperature",
17
+ "relative_humidity_2m": "humidity",
18
+ "wind_speed_10m": "wind_speed"
19
+ }, inplace=True)
20
+
21
+ df["weather_class"] = df["weather_code"].apply(weather_class)
22
+
23
+ features = ["temperature", "humidity", "precipitation",
24
+ "cloud_cover", "wind_speed", "surface_pressure"]
25
+
26
+ df = df.dropna(subset=features + ["weather_class"])
27
+ X = df[features]
28
+ y = df["weather_class"]
29
+
30
+ X_train, X_test, y_train, y_test = train_test_split(
31
+ X, y, test_size=0.2, random_state=42
32
+ )
33
+
34
+ model = DecisionTreeClassifier(random_state=42)
35
+ model.fit(X_train, y_train)
36
+
37
+ print("Accuracy:", accuracy_score(y_test, model.predict(X_test)))
38
+ joblib.dump(model, "model.pkl")
39
+ print("Model saved as model.pkl")
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.4
2
+ Name: sklearn-kit
3
+ Version: 0.1.0
4
+ Summary: sklearn ml library
5
+ Requires-Python: <3.14,>=3.11
@@ -0,0 +1,12 @@
1
+ sklearn_kit/__init__.py,sha256=4m9QpPcG5mRDb5psmhK3dURPlwaFxETYEIoJon-buaQ,31
2
+ sklearn_kit/model.py,sha256=v3W7je-wc417xRQZ-CTcFf6WrOpQ9MSuQZLerRs57RM,380
3
+ sklearn_kit/templates/air_quality/client.py,sha256=RYn2yz2R2kHuTkQN8Kjv6aoHL30F5ApjNXh83ws2j90,709
4
+ sklearn_kit/templates/air_quality/server.py,sha256=Df44Q7F37XhR2X8Xq8ZWcLef8-dVbv09fTMOyvLiKnA,1005
5
+ sklearn_kit/templates/air_quality/train.py,sha256=CscWKbBYU3a-eYm4HLvertwZxZn0i1oQ5Q6MtnpwKIU,689
6
+ sklearn_kit/templates/weather/client.py,sha256=QcfNphthM_brvMD8SCaV8XX4mXt5R6kQCNRlogZG2R8,789
7
+ sklearn_kit/templates/weather/server.py,sha256=oNscRBYo1pHL2jswrXBQyWtF2qWJlC1fQWqaYLNIQA4,1176
8
+ sklearn_kit/templates/weather/train.py,sha256=Z7CSgEE_6d_DoceMXTakVKtVAoD0Lr4ZchYv7yhaAHE,1153
9
+ sklearn_kit-0.1.0.dist-info/METADATA,sha256=RopKrI1ViCpuiPeZgeothSxQjsFLd3CwVIy2JX5vI7M,118
10
+ sklearn_kit-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
11
+ sklearn_kit-0.1.0.dist-info/top_level.txt,sha256=dICH2B_HlUMcl_iaCS1UZTWEeySve-o7OqUCU31XtHs,12
12
+ sklearn_kit-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ sklearn_kit