test upload
Browse files- README.md +12 -8
- linear_regression_model.joblib +3 -0
- model.py +22 -0
- train_and_save_model.py +15 -0
README.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
# Linear Regression Model
|
2 |
+
|
3 |
+
This is a simple linear regression model that returns coefficients and intercept when provided with column names.
|
4 |
+
|
5 |
+
## Usage
|
6 |
+
|
7 |
+
### Input
|
8 |
+
The model takes JSON input with the following structure:
|
9 |
+
```json
|
10 |
+
{
|
11 |
+
"columns": ["feature1", "feature2", "feature3"]
|
12 |
+
}
|
linear_regression_model.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c16213ea0ddeef8034d48cb914e7bf3e85e2c0c491c8c823e41a2a93e98fb062
|
3 |
+
size 559
|
model.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# model.py
|
2 |
+
import joblib
|
3 |
+
|
4 |
+
class LinearRegressionModel:
|
5 |
+
def __init__(self):
|
6 |
+
# Load the model
|
7 |
+
self.model = joblib.load("linear_regression_model.joblib")
|
8 |
+
|
9 |
+
def get_coefficients(self, columns):
|
10 |
+
# Return coefficients as a dictionary with column names as keys
|
11 |
+
coefficients = dict(zip(columns, self.model.coef_.tolist()))
|
12 |
+
intercept = self.model.intercept_
|
13 |
+
return {"coefficients": coefficients, "intercept": intercept}
|
14 |
+
|
15 |
+
# Instantiate the model for inference
|
16 |
+
model = LinearRegressionModel()
|
17 |
+
|
18 |
+
# Sample usage function to demonstrate
|
19 |
+
def predict(inputs):
|
20 |
+
# Assume 'columns' is a key in the inputs dict with a list of column names
|
21 |
+
columns = inputs.get("columns", [])
|
22 |
+
return model.get_coefficients(columns)
|
train_and_save_model.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# train_and_save_model.py
|
2 |
+
from sklearn.linear_model import LinearRegression
|
3 |
+
from sklearn.datasets import make_regression
|
4 |
+
import joblib
|
5 |
+
|
6 |
+
# Generate example data (replace with your own dataset)
|
7 |
+
X, y = make_regression(n_samples=100, n_features=3, noise=0.1, random_state=42)
|
8 |
+
|
9 |
+
# Train the model
|
10 |
+
model = LinearRegression()
|
11 |
+
model.fit(X, y)
|
12 |
+
|
13 |
+
# Save the model to a file
|
14 |
+
joblib.dump(model, "linear_regression_model.joblib")
|
15 |
+
print("Model saved as 'linear_regression_model.joblib'")
|