Simple linear regression is useful for finding the relationship between two continuous variables. One is a predictor or independent variable and the other is a response or dependent variable. It looks for a statistical relationship but not a deterministic relationship. Relationship between two variables is said to be deterministic if one variable can be accurately expressed by the other. For example, using temperature in degrees Celsius it is possible to accurately predict Fahrenheit. Today we are going to create an to use the Machine Learning model of Linear Regression in Android. Android App using TensorFlow Lite Creating a Model Firstly we are going to create a Linear Regression model and train it with the predefined data because we are creating a supervised model. For our example, we are going to create Celsius to Fahrenheit converter. import tensorflow as tf tf (tf ) import numpy as np celsius_q=np.array([- ,- , , , , , , ],dtype= ) fahrenheit_a=np.array([- , , , , , , , ],dtype= ) ,c enumerate(celsius_q): print( .format(c,fahrenheit[i])) io=tf (units= ,input_shape=[ ]) io2=tf (units= ) io3=tf (units= ) io4=tf (units= ) model=tf ([io,io2,io3,io4]) model.compile(loss= ,optimizer=tf ( )) hist=model.fit(celsius_q,fahrenheit_a,epochs= ,verbose=False) .logging .set_verbosity .logging .ERROR 40 10 0 8 15 22 38 40 float 40 14 32 46.4 59 71.6 100.4 104 float for i in "{} degree celsius = {} degree fahrenheit" .keras .layers .Dense 4 1 .keras .layers .Dense 4 .keras .layers .Dense 3 .keras .layers .Dense 1 .keras .Sequential 'mean_squared_error' .keras .optimizers .Adam 0.1 500 print ( ) 'Model Training Finised' Now we will convert this Model into tflite file keras_file= tf (model,keras_file) converter=tf (keras_file) tfmodel = converter.convert() .write(tfmodel) 'cf.h5' .keras .models .save_model .lite .TFLiteConverter .from_keras_model_file open ( , ) "degree.tflite" "wb" At this time we will have a file called degree.tflite Android Studio Create a new project and paste the degree.tflite file in assets folder. Open gradel.build(Module:App) Add these lines after : BuildType { } aaptOptions noCompress "tflite" then add these lines to the : dependencies compile 'org.tensorflow:tensorflow-lite:+' And now you can sync the Gradel to install required TensorFlow files. MainActivity.java Import the TensorFlow Interpreter. ; import org .tensorflow .lite .Interpreter Define the Interpreter as tflite: Interpreter tflite ; Now we have to load the files from the assets folder for that we call the loadModelFile. { tflite = try (loadModelFile()); } ( ex){ . (); } new Interpreter catch Exception ex printStackTrace To load the assets folder file we have to use MappedByteBuffer. MappedByteBuffer load throws IOException{ AssetFileDescriptor fileDescriptor=this.get . ; FileInputStream inputStream= ); FileChannel fileChannel=inputStream.get ; long startOffset=fileDescriptor.get ; long declareLength=fileDescriptor.get ; return fileChannel.map(FileChannel.MapMode.READ_ONLY,startOffset,declareLength); } private ModelFile() Assets() open Fd( ) "degree.tflite" new FileInputStream( . () fileDescriptor getFileDescriptor Channel() StartOffset() DeclaredLength() We have one EditText in the app with variable name et, we will read the value and pass to get the prediction. prediction= . ); float do Inference( . () et getText to String() function has one input array which is a 1D array and ouput will be of the 2D array, so we initialize them and then , we will save the output value and return it to prediction. doInference() tflite.run(input, output) { inputVal= ; inputVal = value ; output= ; tflite.run(inputVal,output); inferredValue=output ; return inferredValue; } private float do Inference(String ) inputString float [] new float [ ] 1 [ ] 0 . Float Of( ) inputString float [] [] new float [ ] 1 [ ] 1 float [ ] 0 [ ] 0 Lastly, we have named hw, we will write the prediction to the . TextView TextView hw.set ) Text(Float. ( ) toString prediction Stay Tuned!