Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python3
- from random import randint
- f = open("leukemia.dat", "r")
- lines = sum(1 for line in open('leukemia.dat'))
- # get 20% of toal lines
- tot = int((int(lines)*20)/100)
- rand_lines = []
- for _ in range(tot):
- #generate random value
- n = randint(1, lines)
- while n in rand_lines:
- n = randint(1, lines)
- # add to the list
- rand_lines.append(n)
- test = open("test.dat","w+")
- train = open("train.dat","w+")
- i=0
- for x in f:
- if i == 0:
- test.write(x)
- train.write(x)
- elif i in rand_lines:
- test.write(x)
- else:
- train.write(x)
- i += 1
- print("Done!")
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement