Spaces:
Runtime error
Runtime error
Download scripts/intro_ml.py from theelvace/weather-data-fetcher-api: direct link, hf CLI and curl.
- Browser
- Download file 829 Bytes
-
https://huggingface.co/spaces/theelvace/weather-data-fetcher-api/resolve/main/scripts/intro_ml.py
- Command line
-
hf download hf://spaces/theelvace/weather-data-fetcher-api/scripts/intro_ml.py
-
curl -L -o intro_ml.py https://huggingface.co/spaces/theelvace/weather-data-fetcher-api/resolve/main/scripts/intro_ml.py
829 Bytes
| from sklearn.linear_model import LinearRegression | |
| import numpy as np | |
| # Imagine 5 days of temperatures (°C) | |
| # `x` is the input feature (temperature), reshaped to a column vector | |
| x = np.array([25, 27, 30, 32, 35]).reshape(-1, 1) | |
| # `y` is the output label (humidity percentage) | |
| y = np.array([50, 55, 63, 70, 74]) | |
| model = LinearRegression() | |
| model.fit(x, y) | |
| pred = model.predict([[28]]) | |
| print(f"Predicted humidity for 28°C: {pred[0]:.2f}%") | |
| import matplotlib.pyplot as plt | |
| plt.scatter(x, y, color='blue', label='data') | |
| plt.plot(x, model.predict(x), color='red', label='model') | |
| plt.xlabel('Temperature (°C)') | |
| plt.ylabel('Humidity (%)') | |
| plt.legend() | |
| plt.tight_layout() | |
| plt.savefig("results/intro_regression.png") | |
| print("✅ Saved results/intro_regression.png") | |
| print("slope:", model.coef_) | |
| print("intercept:", model.intercept_) |