第一个问题:我在编译的时候发现softmax
is not implemented的问题,不知道怎么编写softmax和编写好之后把softmax文件放在哪
第二个问题:如果我把Layer('softmax')删了,编译的时候会显示Mismatch between dataset size and units in output layer.我不知道哪个维数出问题了,大佬可以帮忙解答吗
import numpy as np
import urllib.request
import pandas as pd
from pandas import DataFrame
import numpy as np
import pandas as pd
import xlrd
from sklearn import preprocessing
def excel_to_matrix(path):
table = xlrd.open_workbook(path).sheets()[0] # 获取第一个sheet表
row = table.nrows # 行数
col = table.ncols # 列数
datamatrix = np.zeros((row, col))
for x in range(col):
cols = np.matrix(table.col_values(x))
datamatrix[:, x] = cols
return datamatrix
datafile = u'C:\\Users\\asus\\PycharmProjects\\2\\venv\\Lib\\附件2:数据.xls'
datamatrix=excel_to_matrix(datafile)
data=pd.DataFrame(datamatrix)
y=data[10]
data=data.drop(10,1)
x=data
# print(y.shape)
from sklearn import preprocessing
x_MinMax=preprocessing.MinMaxScaler()
y_MinMax=preprocessing.MinMaxScaler()
y.as_matrix(y)
y=np.array(y).reshape((len(y),1))
x=np.array(x).reshape((len(x),10))
x=x_MinMax.fit_transform(x)
y=y_MinMax.fit_transform(y)
x.mean(axis=0)
import random
from sklearn.cross_validation import train_test_split
np.random.seed(2016)
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2)
from sknn.mlp import Regressor,Layer #预测模型
fit3=Regressor(layers=[Layer('Tanh',units=45),Layer('Tanh',units=18),
Layer('softmax')],
learning_rate=0.02,
random_state=2016,
valid_size=0.25,
dropout_rate=0.2,
learning_momentum=0.30,
batch_size=35,
n_iter=10
)
fit3.fit(x_train,y_train)
from sklearn.metrics import confusion_matrix
predict3_train=fit3.predict(x_train)
score3=fit3.score(x_train,y_train)
confu3=confusion_matrix(y_train,predict3_train)
print(confu3)
score_text3=fit3.score(x_test,y_test)
print(score_text3)
predict3_test=fit3.predict(x_test)
confu3_test=confusion_matrix(y_test,predict3_test)
print(confu3_test)