How to import the MinMaxScaler created in Python into MATLAB
12 次查看(过去 30 天)
显示 更早的评论
Hello everyone! I need to import my neural networks from Python into MATLAB. I am able to do that using the importTensorFlowNetworks command, and use the "predict" function to make predictions in MATLAB with the pre-trained networks on different datasets. The problem here is that the predicted outputs remain in the scaled format, which is understandable since the data which went into the neural network originally in Python was scaled between [-1, 1] for obvious reasons. I tried using different methods in MATLAB to unscale the predicted values and bring them to their original domain. But it is not working accurately. Only if I export these values from MATLAB back into Python again and use the "scaler.inverse_transform" function of the MinMaxScaler(), I am getting accurate results. Does anyone know if I can import this MinMaxScaler() from Python into MATLAB so that I can perform the unscaling in MATLAB itself without having to import the data from MATLAB into Python? Or if anyone has a better alternative, I am open to suggestions.
Regards,
Akshay
0 个评论
回答(1 个)
Yash
2023-10-6
编辑:Yash
2023-10-6
I understand that you are unable to rescale the predicted values back to their original domain. I suspect this is because sklearn.preprocessing.MinMaxScaler "scaler" was fit on the training data and then transformed before being fed to the neural network. The desired results are obtained when using scaler.inverse_transform in Python, since "scaler" object has access to minimum and maximum values of the original data, which the MATLAB code doesn't.
Consider storing the minimum and maximum value of the original data using the below code and import these values into the MATLAB code.
minValue = scaler.data_min_[0].astype(np.float64)
maxValue = scaler.data_max_[0].astype(np.float64)
Now use MATLAB's rescale function to scale the output of the neural network back to the original domain.
scaledOutput = rescale(neuralNetOutput, minValue, maxValue)
Refer here for more information on rescale function: https://www.mathworks.com/help/matlab/ref/rescale.html
I hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!