- Take your Python code and invoke it in MATLAB (yes, MATLAB can call Python code: https://nl.mathworks.com/help/matlab/call-python-libraries.html?searchHighlight=python&s_tid=doc_srchtitle )
- Given that your Python program depends on Keras, and numpy you would need to know exactly what these are doing. Typically MATLAB byitself has everything that numpy does but the Keras part I am not sure how you would translate it other than using the Deep Learning Toolbox: https://nl.mathworks.com/help/deeplearning/examples/assemble-network-from-pretrained-keras-layers.html?searchHighlight=keras&s_tid=doc_srchtitle
how to convert python code to MATLAB?
34 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
np.random.seed(3)
# 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'])
model.fit(x_train, y_train, batch_size=15, epochs=2500, validation_data=(x_test, y_test))
please!
1 Kommentar
GT
am 17 Dez. 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
Antworten (2)
Abderrahmane Bakhouche
am 20 Feb. 2022
# Metamodel regression
X_train, X_test, y_train, y_test = \
train_test_split(LDB1.iloc[:,:-1], LDB1["d"], test_size=0.4, random_state=42)
clf = make_pipeline(SplineTransformer(),
MLPRegressor(alpha=0.0001, hidden_layer_sizes = (20, 10), max_iter = 500000,
activation = 'relu', verbose = 'True', learning_rate_init=0.01))
a = clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
plt.figure()
# plt.scatter(X_train[P])
plt.scatter(X_test["P"], y_test.tolist(), label="Test values")
plt.scatter(X_test["P"], y_pred, label="Predicted values") # plot network output
plt.title("P vs d (Predicted and test values")
plt.legend()
0 Kommentare
David Willingham
am 30 Sep. 2020
Bearbeitet: David Willingham
am 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:
https://www.mathworks.com/help/deeplearning/ref/importtensorflownetwork.html
For other frameworks, you can import and export via ONNX:
Regards,
Deep Learning Product Manager, MathWorks
0 Kommentare
Siehe auch
Kategorien
Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!