欢迎访问宙启技术站
智能推送

随机生成的aligned_dataset()数据集示例(使用Python)

发布时间:2023-12-11 05:43:52

以下是一个示例代码,用于生成一个包含1000个数据样本的随机生成的aligned_dataset()数据集。

import numpy as np

def aligned_dataset(num_samples, num_features):
    # 随机生成特征矩阵
    features = np.random.rand(num_samples, num_features)
    
    # 随机生成标签矩阵,且与特征矩阵的行对齐
    labels = np.random.randint(low=0, high=2, size=num_samples)
    
    return features, labels

# 生成一个包含1000个数据样本,每个样本有10个特征的数据集
num_samples = 1000
num_features = 10
dataset = aligned_dataset(num_samples, num_features)

# 打印数据集的形状
print("Features shape:", dataset[0].shape)
print("Labels shape:", dataset[1].shape)

# 打印数据集的前5个数据样本
print("First 5 samples:")
for i in range(5):
    print("Features:", dataset[0][i])
    print("Label:", dataset[1][i])
    print("---")

此代码将生成一个形状为(1000, 10)的特征矩阵,其中每个样本有10个特征。它还生成一个形状为(1000,)的标签矩阵,其中包含1000个随机选择的0或1的标签。您可以将这个函数调整为适应您特定的数据集需求。

输出示例:

Features shape: (1000, 10)
Labels shape: (1000,)
First 5 samples:
Features: [0.28110992 0.54831396 0.67548559 0.34563178 0.53146853 0.60319555
 0.64936124 0.66830006 0.90255445 0.68007586]
Label: 1
---
Features: [0.07585043 0.89792174 0.39984382 0.35665141 0.82392932 0.10970677
 0.69265979 0.21739098 0.33210344 0.22842121]
Label: 0
---
Features: [0.31949205 0.78066875 0.69370565 0.76041189 0.30375678 0.53737716
 0.9815794  0.91408439 0.61749419 0.17945042]
Label: 1
---
Features: [0.6861469  0.21113025 0.55676981 0.97571303 0.40635396 0.36281506
 0.70602264 0.27131992 0.9932243  0.70763249]
Label: 0
---
Features: [0.18963312 0.65042027 0.70637886 0.33558284 0.01005292 0.39856423
 0.16294236 0.68362413 0.15190664 0.45415088]
Label: 1
---

这个例子演示了如何使用aligned_dataset()函数生成一个随机的数据集,并打印出数据集的形状以及前5个样本的特征和标签。您可以根据需要使用这个数据集进行任何机器学习任务。