BNClassifier.XYfromCSV

BNClassifier.XYfromCSV(filename, with_labels=True, target=None)

Reads the data from a csv file and separates it into an X matrix and a y column vector.

Parameters:
  • filename (str) – the name of the csv file

  • with_labels (bool) – tells us whether the csv includes the labels themselves or their indexes.

  • target (str or None) – The name of the column that will be put in the dataframe y. If target is None, we use the target that is already specified in the classifier

Returns:

Matrix X containing the data,Column-vector containing the class for each data vector in X

Return type:

Tuple(pandas.Dataframe,pandas.Dataframe)

Example

import pyagrum as gum
import pyagrum.skbn as skbn
from pyagrum.lib.discreteTypeProcessor import DiscreteTypeProcessor

gum.initRandom(42)
bn = gum.fastBN("A->Y<-B;Y->C")
gum.generateSample(bn, 500, "data.csv")
clf = skbn.BNClassifier(type_processor=DiscreteTypeProcessor())
X, y = clf.XYfromCSV("data.csv", target="Y")
list(X.columns)
# ['C', 'B', 'A']
y.name, len(y)
# ('Y', 500)

Class

BNClassifier