Linear Regression

Crux

Given a set of features and their predetermined outcomes, a dependency can be formed between the two which can be used to extrapolate or interpolate outcome of an unknown feature set.
More Details : Wikipedia

Login

Request

POST /api/login/ HTTP/1.1
Content-Type: application/json

{
    "username": "username",
    "password": "password"
}

Response

{
    "token": "abcd12345"
}
Use the token received to access the endpoints. Add the header as shown in every request. Remember, the token is valid for next 10 minutes
Authorization: JWT abcd12345

API Commons

Action

Every request should contain action which guides the system to perform specific procedures
Action Description
new_model Creates a new model and saves it to database
predict Use the saved model to predict output for given data
delete Delete the model from database
get_coefficients Get the coefficients which are used for prediction

Training : Compute Final Score of Exam

You are a Physics student who appeared for the final exams and very impatient to know your final score. But the teacher who grades you is insanely strict. He assigns different weights to the exams Physics students take but no one knows the magic formula (which is 0.5 * Paper_1 + 2 * Paper_2 + Paper_3) - its a secret but will need it to verify the prediction). You have a list of your friends' exam scores and final aggregate and want to calculate yours.

Request

POST /api/linear_regression/ HTTP/1.1
Content-Type: application/json
Accept: application/json
Authorization: JWT abcd12345

{
	"action": "new_model",
	"name": "Compute Final Score",
	"input_x": [[9.5, 8.75, 6.9], [9.9, 4.8, 5.45], [8.5, 5.7, 9.8], [9, 9.5, 9.1]],
	"input_y": [29.15, 20, 25.45, 32.6]
}

Response

{
    "status": "Trained",
    "model_id": "58e37bb568b9b62d3d8a3818"
}

Prediction : Compute Final Score of Exam

Now, you provide the model with yours along with your best friend's scores and it computes the best possible solution. According to the magic formula, scores should be 32.6 & 26.5

Request

POST /api/linear_regression/ HTTP/1.1
Content-Type: application/json
Accept: application/json
Authorization: JWT abcd12345

{
	"action": "predict",
	"model_id": "58e37bb568b9b62d3d8a3818",
	"input_x": [[9, 9.5, 9.1], [8, 8, 6.5]]
}

Response

{
    "status": "OK",
    "prediction": [
        32.6,
        26.499999999999957
    ]
}