2

I have written a python code for text classifier using SVM (Multi-class), now I want to run this code in the android application. TensorFlow-lite is useful in this scenario from what I have read, how should I proceed to work to convert my python code to TensorFlow-lite code? what should steps that I need to follow?

Below is the code for SVM Classifier,

import pandas as pd
import numpy as np
import tensorflow as tf
from collections import Counter
from sklearn import model_selection, preprocessing, linear_model, naive_bayes, metrics, svm
from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.svm import SVC

column_names = ['text', 'labels'] 
data = pd.read_csv("newdataset.csv", names = column_names, index_col = False)

train_x, test_x, train_y, test_y = model_selection.train_test_split(data.text,data.labels,test_size = 0.5 ,random_state = 0)

count_vect = CountVectorizer(analyzer='word', token_pattern=r'\w{1,}',max_features=100)
count_vect.fit(data.text)
xtrain_count =  count_vect.transform(train_x)
xtest_count =  count_vect.transform(test_x)

tfidf_vect = TfidfTransformer()
xtrain_tfidf =  tfidf_vect.fit_transform(xtrain_count)
xtest_tfidf =  tfidf_vect.fit_transform(xtest_count)

clf = svm.SVC(kernel='linear')
clf.fit(xtrain_tfidf, train_y)

predicted = clf.predict(xtest_tfidf)

from sklearn.metrics import classification_report, confusion_matrix, accuracy_score

print(confusion_matrix(test_y,predicted))
print(classification_report(test_y,predicted))
print(accuracy_score(test_y,predicted))

0 Answers0