从我的MATLAB代码中,我用八度音阶提取MAT文件:
dateforname = "autogenerated_m_" + datetime.datetime.now().strftime("%m_%d_%y%H_%M_%S")
saveworkspace = "save -v7 " + currentdirpath + "\\" + newfoldername + "\\" + dateforname + "_workspace.mat"
saveworkspace = saveworkspace.replace('\\', '/')
# Ideas from: https://stackoverflow.com/questions/45525233/loading-mat-and-m-files-with-loadmat-in-python
oct.eval("Generate_Data")
oct.eval(saveworkspace)
我以这种方式从这些MAT文件读取并创建NumPy数组:
from scipy.io import loadmat
import numpy as np
D = loadmat("xxx/09_07_1913_44_15_workspace.mat")
print(D.keys())
print("------------------")
#print(D['As'])
for item in D.keys():
if not any(value in item for value in ("__header__", "__globals__","__version__")):
print(item)
print(D[item])
print("-----")
matrix = D[item]
print(matrix.flatten()) #We can also use the Flatten method to convert a matrix to 1-d array
# Alternative to flatten: Reshape
# print(matrix.reshape(9,1))#Here -1 says as many columns as needed and 1 row
# print(matrix.reshape(1,-1))#If we provide only 1 value Reshape would return a 1-d array of that length
这就是我迷路的地方。我有一个扁平的结构,我想把它作为一个模型预测。我该怎么做?你知道吗
换句话说,每个MAT文件都是一条包含多个特征的线,每个特征都是一个“复杂”对象(NumPy数组)。这些特征不仅是一个数字,而且应该是从MAT文件中提取的扁平结构。有办法吗?你知道吗
这就是我一直在尝试的:
#X, y = make_blobs(n_samples=100, centers=2, n_features=2, random_state=1)
X = D["as"],D["Ff0"],D["Ff1"]
y = D["ans"] # This is a feature from my .mat
scalar = MinMaxScaler()
scalar.fit(X)
X = scalar.transform(X)
# define and fit the final model
model = Sequential()
model.add(Dense(4, input_dim=2, activation='relu'))
model.add(Dense(4, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam')
model.fit(X, y, epochs=200, verbose=0)
传递这样的特性有意义吗?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐