python判断性别程序_关于 python机器学习 根据中文名字 判断性别

完整代码如下: name.csv 需要自己采集数据import tensorflow as tfname_dataset = './name.csv'train_x = []train_y = []with open(name_dataset, 'r',encoding='UTF-8') as f:first_line = Truefor line in f:if first_line is Tr...
摘要由CSDN通过智能技术生成

完整代码如下: name.csv 需要自己采集数据import tensorflow as tf

name_dataset = './name.csv'

train_x = []

train_y = []

with open(name_dataset, 'r',encoding='UTF-8') as f:

first_line = True

for line in f:

if first_line is True:

first_line = False

continue

sample = line.strip().split(',')

if len(sample) == 2:

train_x.append(sample[0])

if sample[1] == '男':

train_y.append([0, 1]) # 男

else:

train_y.append([1, 0]) # 女

max_name_length = max([len(name) for name in train_x])

# print("最长名字的字符数: ", max_name_length)

max_name_length = 8

counter = 0

vocabulary = {}

for name in train_x:

counter += 1

tokens = [word for word in name]

for word in tokens:

if word in vocabulary:

vo

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值