将excel表格类的数据保存为文本文档(制表符格式)
python代码
"""
#-*- coding: utf-8 -*-
"""
from numpy import *
from sklearn.metrics import classification_report
from sklearn.neural_network import MLPClassifier
table = []
with open("sjwldzy.txt") as f:
for line in f:
one_line=line.strip("\n").split("\t")
num_one_line=list(map(int,one_line))
table.append(num_one_line)
table=mat(table)
train_data=table[:,0:4]
trian_lab=table[:,4]
def read():
bp = MLPClassifier(hidden_layer_sizes=(50,), activation='relu',
solver='lbfgs', alpha=0.0001, batch_size='auto',
learning_rate='constant')
bp.fit(train_data, trian_lab.astype('int'))
y_predict = bp.predict(train_data)
y_test1 = trian_lab.tolist()
y_predict = list(y_predict)
for i in range(len(y_test1)):
y_test1[i] = y_test1[i]
print('BP网络:\n', classification_report(trian_lab.astype('int'), y_predict))
print("真实数据:\t", y_test1)
print("预测数据:\t", y_predict)
if __name__ == "__main__":
read()