【发布时间】:2015-09-28 05:25:20
【问题描述】:
我的问题:
我有一个大型 JSON 文件的数据集。我读取它并将其存储在trainList 变量中。
接下来,我对其进行预处理 - 以便能够使用它。
完成后我开始分类:
- 我使用
kfold交叉验证方法来获得均值 准确度并训练分类器。 - 我做出预测并获得该折叠的准确性和混淆矩阵。
- 在此之后,我想获得
True Positive(TP)、True Negative(TN)、False Positive(FP)和False Negative(FN)值。我将使用这些参数来获得 Sensitivity 和 Specificity。
最后,我会用它来放入 HTML 中,以便显示带有每个标签的 TP 的图表。
代码:
我目前拥有的变量:
trainList #It is a list with all the data of my dataset in JSON form
labelList #It is a list with all the labels of my data
大部分方法:
#I transform the data from JSON form to a numerical one
X=vec.fit_transform(trainList)
#I scale the matrix (don't know why but without it, it makes an error)
X=preprocessing.scale(X.toarray())
#I generate a KFold in order to make cross validation
kf = KFold(len(X), n_folds=10, indices=True, shuffle=True, random_state=1)
#I start the cross validation
for train_indices, test_indices in kf:
X_train=[X[ii] for ii in train_indices]
X_test=[X[ii] for ii in test_indices]
y_train=[listaLabels[ii] for ii in train_indices]
y_test=[listaLabels[ii] for ii in test_indices]
#I train the classifier
trained=qda.fit(X_train,y_train)
#I make the predictions
predicted=qda.predict(X_test)
#I obtain the accuracy of this fold
ac=accuracy_score(predicted,y_test)
#I obtain the confusion matrix
cm=confusion_matrix(y_test, predicted)
#I should calculate the TP,TN, FP and FN
#I don't know how to continue
【问题讨论】:
标签: python machine-learning scikit-learn classification supervised-learning