This repository hosts a simple linear regression model. The model provides two primary functions:
Send a JSON payload with just column names to retrieve the model’s coefficients and intercept.
1{
2 "inputs": {
3 "columns": ["feature1", "feature2", "feature3"]
4 }
5}
1{
2 "coefficients": {"feature1": 0.5, "feature2": -1.2, "feature3": 2.3},
3 "intercept": 0.1
4}
Send a request with column names and a CSV file containing data for prediction. The model will use the data in the specified columns to make predictions.
1import requests
2
3url = "https://api-inference.huggingface.co/models/your-username/linear-regression-model"
4headers = {"Authorization": "Bearer YOUR_HUGGINGFACE_API_TOKEN"}
5
6# Define the columns and open the CSV file in binary mode
7columns = ["feature1", "feature2", "feature3"]
8files = {
9 "inputs": ("data.csv", open("path/to/your/data.csv", "rb")),
10 "columns": (None, str(columns)) # Send columns as JSON string
11}
12
13response = requests.post(url, headers=headers, files=files)
14print(response.json())
1curl -X POST "https://api-inference.huggingface.co/models/your-username/linear-regression-model" \
2 -H "Authorization: Bearer YOUR_HUGGINGFACE_API_TOKEN" \
3 -F "columns=['feature1', 'feature2', 'feature3']" \
4 -F "inputs=@path/to/your/data.csv"
1{
2 "predictions": [10.5, 15.8, 12.3]
3}
This setup allows users to choose between retrieving coefficients or making predictions based on CSV data for more flexibility.