1

我对 python 和 scikit-learn 都很陌生。我的目标是获得一个分类工作,该分类应该分为 6 个不同的字符串标签,并带有一个深度信念网络。

以下是我的一些数据示例:

uploadType,mainColorCode,allPageHeights,allPageWidths,mainAspectRatio,hasQrOrBarcode,mainFontSize,ocrWords,ocrNumber,pageCount,category

Filesystem,#FFFFFFFF,1115 1115,794 794,0.71,False,20.15,ocr 识别文本,14.4,2,class a 文件系统,#FFFFFFFF,1115 1115,794 794,0.71,False,20.15,ocr 识别文本,0, 2,class a Filesystem,#FFFFFFFF,1056,816,0.77,False,19.61,ocr识别文本,204.2,1,class b

我得到包含 11 列(10 个特征,最后一个是标签)的监督数据,如下所示:

input_file = "Downloads/data.csv"
df = pd.read_csv(input_file, header = 0)
original_headers = list(df.columns.values)
df = df._get_numeric_data()
numeric_headers = list(df.columns.values)
reverse_df = df[numeric_headers]
numpy_array = reverse_df.as_matrix()
X, Y = numpy_array[:,1:], numpy_array[:,0]

然后我做:

# Splitting data
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=0)

# Data scaling
min_max_scaler = MinMaxScaler()
X_train = min_max_scaler.fit_transform(X_train)

# Training
classifier = SupervisedDBNClassification(hidden_layers_structure=[256, 256],
                                         learning_rate_rbm=0.01,
                                         learning_rate=0.001,
                                         n_epochs_rbm=20,
                                         n_iter_backprop=100,
                                         l2_regularization=0.0,
                                         activation_function='relu')
classifier.fit(X_train, Y_train)

# Test
X_test = min_max_scaler.transform(X_test)
Y_pred = classifier.predict(X_test)
print 'Done.\nAccuracy: %f' % accuracy_score(Y_test, Y_pred)

但它说我:ValueError:

无法处理未知和二进制的混合

我想我必须对数据执行以下语句,但我不确定如何正确地对数据执行它:

le = preprocessing.LabelEncoder()
le.fit(["Class A", "Class B", "Class C", "Class D", "Class E", "Class F"])

谢谢!

4

0 回答 0