3

我正在练习 TF learn 如何使用 pandas 和 titanic 数据集。我想我掌握了它的窍门,但是在拟合我的模型时它崩溃了,我不知道为什么。我想这与我转换的方式有关,inputX and inputY但我不太确定,我认为这是正确的。

import numpy as np
import tensorflow as tf
import tflearn
import pandas as pd

# Download the Titanic dataset
from tflearn.datasets import titanic
titanic.download_dataset('titanic_dataset.csv')

from tflearn.data_utils import load_csv
dataframe = pd.read_csv('titanic_dataset.csv')

# okay lets drop the rest of the stuff from the table and keep those.
dataframe = dataframe.drop(["name", "ticket"], axis=1)

#lets change sex female/male to 1 and 0
dataframe['sex'].replace(['female','male'],[1,0],inplace=True)

# lets convert them so the tlearn can use doesnt crash
inputX = dataframe.loc[:, ['pclass', 'sex', 'age', 'sibsp', 'parch', 'fare']].as_matrix()
dataframe.loc[:, ("survived2")] = dataframe["survived"] == 0           
dataframe.loc[:, ("survived2")] = dataframe["survived2"].astype(int)
inputY = dataframe.loc[:, ["survived", "survived2"]].as_matrix()

def NN():
    net = tflearn.input_data(shape=[None, 6])
    net = tflearn.fully_connected(net, 32)
    net = tflearn.fully_connected(net, 32)
    net = tflearn.fully_connected(net, 2, activation='softmax')
    net = tflearn.regression(net)
    # This model assumes that your network is named "net"    
    model = tflearn.DNN(net)
    return model

# Define model
model = NN()
# Start training (apply gradient descent algorithm)
# Training
model.fit(inputX, inputY, validation_set=0.1, show_metric=True, batch_size=100, n_epoch=8)

这是错误图片在此处输入图像描述

4

0 回答 0