Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def generate_row(label):
- if label == 1:
- intervals = [(0.0, 0.1), (0.2, 0.3), (0.4, 0.5), (0.6, 0.7), (0.8, 0.9)]
- else:
- intervals = [(0.1, 0.2), (0.3, 0.4), (0.5, 0.6), (0.7, 0.8), (0.9, 1.0)]
- row = []
- for i in range(4): # každé dva sloupce z jednoho intervalu
- interval = intervals[i]
- row.extend(np.random.uniform(interval[0], interval[1],1))
- row.append(label)
- return row
- # Vytvoření matice 50x6
- rows, cols = 50, 4
- matrix = []
- for _ in range(rows):
- label = np.random.choice([0, 1])
- row = generate_row(label)
- matrix.append(row)
- # Zamíchejte 10 % labelů
- num_labels_to_shuffle = int(rows)
- indices_to_shuffle = np.random.choice(rows, num_labels_to_shuffle, replace=True)
- # Extrahujte a zamíchejte vybrané labely
- labels_to_shuffle = [matrix[i][-1] for i in indices_to_shuffle]
- np.random.shuffle(labels_to_shuffle)
- # Aktualizujte původní matici s novými, zamíchanými labely
- for i, idx in enumerate(indices_to_shuffle):
- matrix[idx][-1] = labels_to_shuffle[i]
- # Tisk matice s hranatými závorkami pro jednotlivé řádky oddělené čárkami
- output = ",\n".join(f"[{','.join(map(str, row))}]" for row in matrix)
- print(output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement