Instructions to use Udyan/SimpleRegression with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use Udyan/SimpleRegression with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("Udyan/SimpleRegression", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
| import gradio as gr | |
| import csv | |
| import os | |
| from datetime import datetime | |
| import pandas as pd | |
| from sklearn.linear_model import LinearRegression | |
| import time | |
| active_count = 0 | |
| model = None | |
| def log_data(count): | |
| file_exists = os.path.isfile("usage.csv") | |
| with open("usage.csv", "a", newline="") as f: | |
| writer = csv.writer(f) | |
| if not file_exists: | |
| writer.writerow(["time", "active_users"]) | |
| writer.writerow([datetime.now(), count]) | |
| def train_model(): | |
| global model | |
| if not os.path.exists("usage.csv"): | |
| return None | |
| data = pd.read_csv("usage.csv") | |
| if len(data) < 2: | |
| return None | |
| data['time'] = pd.to_datetime(data['time']) | |
| data['time'] = data['time'].astype(int) // 10**9 | |
| X = data[['time']] | |
| y = data['active_users'] | |
| model = LinearRegression() | |
| model.fit(X, y) | |
| def predict(input_text): | |
| global active_count, model | |
| # increase count | |
| active_count += 1 | |
| # log data | |
| log_data(active_count) | |
| # train model | |
| train_model() | |
| # prediction | |
| if model: | |
| current_time = int(time.time()) | |
| pred = model.predict([[current_time]])[0] | |
| return f"Estimated Active Users: {int(pred)}" | |
| else: | |
| return f"Current Active Users (approx): {active_count}" | |
| iface = gr.Interface( | |
| fn=predict, | |
| inputs="text", | |
| outputs="text", | |
| title="Active Users Predictor" | |
| ) | |
| iface.launch(share = True) |