我对python和scikit-learn都很陌生。我的目标是让分类工作分为6个不同的字符串标签和深信念网。
以下是我的数据的一些示例:
uploadType,mainColorCode,allPageHeights,allPageWidths,mainAspectRatio,hasQrOrBarcode,mainFontSize,ocrWords,ocrNumber,PAGECOUNT,类
Filesystem,#FFFFFFFF,1115 1115,794 794,0.71,False,20.15,ocr已识别 text,14.4,2,class a Filesystem,#FFFFFFFF,1115 1115,794 794,0.71,False,20.15,ocr识别文本,0,2,类a 文件系统,#FFFFFFFF,1056,816,0.77,False,19.61,ocr识别 文字,204.2,1,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"])
谢谢!