0

I am using NFStream to analyse network traffic from live interface and RanfomForestClassifier to predict the traffic category (web, video, voice,...). I already fitted the model. I had the same error while fitting the model but i solved it with LabelEncoder.

Here i just loaded my model from another file:

filename = "fitted_model"
loaded_model = joblib.load(filename)

Then i created the function that will give me predictions on a live network interface:

    class ModelPrediction(NFPlugin):
def on_init(self, packet, flow):
    flow.udps.model_prediction = 0
def on_expire(self, flow):
    to_predict = np.asarray([flow.src_port, flow.dst_port, flow.protocol,
              flow.application_name, flow.bidirectional_bytes]).reshape((1,-1))
    flow.udps.model_prediction = self.my_model.predict(to_predict)

Finally i just want to print these predictions (NFStreamer is the function that allows the live capture):

ml_streamer = NFStreamer(source="ens160", udps=ModelPrediction(my_model=loaded_model))
for flow in ml_streamer:
    print(le.inverse_transform(flow.udps.model_prediction))

The error :

 File "deployml.py", line 23, in on_expire
 flow.udps.model_prediction = self.my_model.predict(to_predict)
 ValueError: could not convert string to float: 'Facebook'

The error occurs while converting flow.application_name into float

  • Does this answer your question? [How do I parse a string to a float or int?](https://stackoverflow.com/questions/379906/how-do-i-parse-a-string-to-a-float-or-int) –  Apr 23 '22 at 17:56

0 Answers0