SVM Classifier

Crux

Instances can be classified or divided by imaginary hyperplanes acting as a boundary
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

Training : GPS Coordinates of Nevada & Kansas

The GPS coordinates of three random locations in each of the state of US - Nevada and Kansas are used as training data. The first three are the locations in Nevada and rest three in Kansas.

Request

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

{
	"action": "new_model",
	"name": "Classify Area on the basis of GPS coords",
	"input_x": [[40.239230, -117.998445], [40.339793, -114.702547], [37.328181, -115.537507],
                [37.432941, -101.079500], [39.531108, -97.036531], [37.572392, -95.542390]],
	"input_y": ["Nevada", "Nevada", "Nevada", "Kansas", "Kansas", "Kansas"]
}

Response

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

Prediction : GPS Coordinates of Nevada & Kansas

Now, the model is provided with a new location which was not used before. The model will assess and respond with one of the two states.

Request

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

{
	"action": "predict",
	"model_id": "58e3657868b9b6147505f1fc",
	"input_x": [[38.369171, -99.761140], [40.597344, -114.925079]]
}

Response

{
    "prediction": [
        "Kansas",
        "Nevada"
    ],
    "status": "OK"
}

Specific Notes

  • "new_model" optional arguments :

    • c

      Penalty parameter C of the error term

      {
          "action": "new_model",
          "c": 2.0,
          "name": ...,
          "input_x": ...
          "input_y": ...
      }