how to convert python code to MATLAB?

337 views (last 30 days)
Min-seok Kim
Min-seok Kim on 14 Dec 2018
Edited: David Willingham on 27 Apr 2021
Is there way to convert this python code to matlab code?
it's too hard to me :(
how to convert python to matlab???
this is code what I want to convert.
from sklearn.model_selection import train_test_split
import keras
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
# number of wine classes
classifications = 3
# load dataset
dataset = np.loadtxt('wine.csv', delimiter=",")
# split dataset into sets for testing and training
X = dataset[:,1:14]
Y = dataset[:,0:1]
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.66, random_state=5)
# convert output values to one-hot
y_train = keras.utils.to_categorical(y_train-1, classifications)
y_test = keras.utils.to_categorical(y_test-1, classifications)
# creating model
model = Sequential()
model.add(Dense(10, input_dim=13, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(6, activation='relu'))
model.add(Dense(6, activation='relu'))
model.add(Dense(4, activation='relu'))
model.add(Dense(2, activation='relu'))
model.add(Dense(classifications, activation='softmax'))
# compile and fit model
model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=['accuracy']), y_train, batch_size=15, epochs=2500, validation_data=(x_test, y_test))
  1 Comment
GT on 17 Dec 2018
To the best of my knowledge there is no "automatic" python to MATLAB converter. There are a couple of things you can do:
Hope that this helps

Sign in to comment.

Answers (1)

David Willingham
David Willingham on 30 Sep 2020
Edited: David Willingham on 27 Apr 2021
For Deep Learning there are a few ways to import and export networks into MATLAB.
MATLAB has a direct Tensorflow Importer you could use to import the network:
For other frameworks, you can import and export via ONNX:
Deep Learning Product Manager, MathWorks





Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by