# coding=utf-8
import pandas as pd
import numpy as np
from sklearn import cross_validation
import tensorflow as tf global flag
flag=0 def DataPreprocessing():
abalone = pd.read_csv("ceshi.csv", sep=',', header=0, keep_default_na=True,na_values=[])
X_train=np.array(abalone.iloc[:,:4])
Y_train=np.array(abalone.iloc[:,4:])
# Y_train=[]
# for i in range(len(X_train)):
# if X_train[i][0] == 'M':
# X_train[i][0]=0
# elif X_train[i][0]=='F':
# X_train[i][0]=1
# else:
# X_train[i][0]=2
#
# for i in range(len(Y_train_)):
#
# #print(Y_train[i][0])
# Y_train.append(Y_train_[i][0]) # print(X_train)
# print(len(X_train))
# print(Y_train)
# print(len(Y_train))
# print(min(Y_train))
# print(max(Y_train)) return cross_validation.train_test_split(X_train,Y_train,test_size=0.25,random_state=0,stratify=Y_train) def GetInputs():
global flag
X_train, X_test, Y_train, Y_test = DataPreprocessing() #print(X_train)
# print(len(X_test))
# print(len(Y_train))
# print(len(Y_test)) #X_train[X_train.isnull().any(axis=1)]
#X_train.fillna('',inplace=True) print(X_train)
print(Y_test) x_train=tf.constant(X_train)
y_train=tf.constant(Y_train)
x_test=tf.constant(X_test)
y_test=tf.constant(Y_test) print(x_train)
print(y_train)
print(x_test)
print(y_test) if flag==0:
return x_train,y_train
else:
return x_test,y_test def Main(): global flag feature_columns=[tf.contrib.layers.real_valued_column("",dimension=4)] clf=tf.contrib.learn.DNNClassifier(feature_columns=feature_columns,hidden_units=[10,20,10],n_classes=2,model_dir="/home/jiangjing/TensorflowModel/banknote") clf.fit(input_fn=GetInputs,steps=2000) flag=1
accuracy_score=clf.evaluate(input_fn=GetInputs,steps=1)["accuracy"] print("nTest Accuracy:{0:f}".format(accuracy_score)) if __name__ =="__main__":
#DataPreprocessing() Main() exit(0)
05-11 11:07