9951 explained code solutions for 126 technologies


python-scikit-learnHow to generate dataset for classification


import numpy as np
from sklearn import datasets

X, y = datasets.make_classification(100, 5, n_classes=2)ctrl + c
from sklearn import

import module from scikit-learn

import numpy

import Numpy module

X, y

loaded features data (X) and target variable (y) values

datasets

predefined datasets to play with

make_classification

generates dataset for classification models

100

number of generated objects

5

number of features

n_classes

number of generated classes


Usage example

import numpy as np
from sklearn import datasets

X, y = datasets.make_classification(100, 5, n_classes=2)

print(X.shape)
print(y)
output
(100, 5)
[1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0
 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 0 1 1 0 1 0 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1
 0 1 0 0 0 1 0 1 0 0 0 1 1 1 1 0 1 0 0 0 0 0 1 0 1 1]