YAML Metadata
Warning:
empty or missing yaml metadata in repo card
(https://huggingface.co/docs/hub/model-cards#model-card-metadata)
Linear Regression Model
This repository hosts a simple linear regression model. The model provides two primary functions:
- Retrieve Coefficients and Intercept: Given column names, the model will return its coefficients and intercept.
- Predict Values from CSV: Given column names and a CSV file with data, the model will use the data to predict values.
Model Files
linear_regression_model.joblib
: The trained linear regression model, saved with joblib.model.py
: Contains the model class and custom Hugging Face pipeline for processing inputs and returning outputs.
Usage
1. Retrieve Coefficients and Intercept
Send a JSON payload with just column names to retrieve the model’s coefficients and intercept.
Input JSON Example:
{
"inputs": {
"columns": ["feature1", "feature2", "feature3"]
}
}
Response JSON Example:
{
"coefficients": {"feature1": 0.5, "feature2": -1.2, "feature3": 2.3},
"intercept": 0.1
}
2. Predict Values from CSV
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.
- Columns: A JSON list of strings specifying the column names used in the model.
- CSV File: A file containing the data rows, uploaded as binary content.
Python Example Using requests
:
import requests
url = "https://api-inference.huggingface.co/models/your-username/linear-regression-model"
headers = {"Authorization": "Bearer YOUR_HUGGINGFACE_API_TOKEN"}
# Define the columns and open the CSV file in binary mode
columns = ["feature1", "feature2", "feature3"]
files = {
"inputs": ("data.csv", open("path/to/your/data.csv", "rb")),
"columns": (None, str(columns)) # Send columns as JSON string
}
response = requests.post(url, headers=headers, files=files)
print(response.json())
curl Example:
curl -X POST "https://api-inference.huggingface.co/models/your-username/linear-regression-model" \
-H "Authorization: Bearer YOUR_HUGGINGFACE_API_TOKEN" \
-F "columns=['feature1', 'feature2', 'feature3']" \
-F "inputs=@path/to/your/data.csv"
Response JSON Example:
{
"predictions": [10.5, 15.8, 12.3]
}
3. File Structure
The main files in this repository:
linear_regression_model.joblib
: Contains the trained linear regression model.model.py
: Model and pipeline definitions, handling CSV input and returning predictions or coefficients.README.md
: This file, explaining model functionality and usage.
Notes
- Ensure your CSV file includes the specified columns for accurate predictions.
- The CSV file is temporarily saved and used for predictions. It will not be stored permanently.
- Your API token is required to authenticate requests.
This setup allows users to choose between retrieving coefficients or making predictions based on CSV data for more flexibility.