Kaggle Titanic solution 纯规则学习
其实就是把train.csv拿出来看了看,找了找规律,调了调参数而已。
找到如下规律:
1.男的容易死,女的容易活
2.一等舱活,三等舱死
3.老人死,小孩活
4.兄弟姐妹多者死
5.票价高的活
6.有Cabin记录的活
然后规则跑一跑,调一调参数,就把今天的提交次数用满了,然后跑到0.77了
import pandas
import numpy
import csv
csv_reader = csv.reader(open('test.csv',encoding='utf-8'))
writer = csv.writer(open('ans.csv','w'))
writer.writerow(list(['PassengerID','Survived']))
data = []
A = 0
B = 0
for row in csv_reader:
if(row[0][0]=='P'):
continue
now = 0
# 一等舱获救,三等舱死亡
if(row[1][0]=='1'):
now=now+1;
if(row[1][0]=='3'):
now=now-1;
# 男的死亡,女性获救
if(row[3][0]=='f'):
now=now+2;
if(row[3][0]=='m'):
now=now-1;
# 老人死亡,年轻人获救
if(len(row[4])>0):
if(float(row[4])<=15):
now=now+1;
if(float(row[4])>=35):
now=now-1;
# 兄弟姐妹多的死掉
if(float(row[5])>1):
now = now-1;
# 财富高的活着,财富低的死亡
if(len(row[8])>0):
if(float(row[8])>100):
now=now+1;
if(float(row[8])<5):
now=now-1;
# 有Cabin的活着,无的死亡
if(row[9] == None):
now=now+1
if(now>0):
data.append([row[0],1])
print([row[0],1,now])
A = A + 1
else:
data.append([row[0],0])
print([row[0],0,now])
B = B + 1
print(A,B)
writer.writerows(data)