本文整理汇总了Python中sklearn.discriminant_analysis.LinearDiscriminantAnalysis.decision_function方法的典型用法代码示例。如果您正苦于以下问题:Python LinearDiscriminantAnalysis.decision_function方法的具体用法?Python LinearDiscriminantAnalysis.decision_function怎么用?Python LinearDiscriminantAnalysis.decision_function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.discriminant_analysis.LinearDiscriminantAnalysis
的用法示例。
在下文中一共展示了LinearDiscriminantAnalysis.decision_function方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: timer
# 需要导入模块: from sklearn.discriminant_analysis import LinearDiscriminantAnalysis [as 别名]
# 或者: from sklearn.discriminant_analysis.LinearDiscriminantAnalysis import decision_function [as 别名]
print "done generating"
X = np.array(arr1)
y = np.array(arr2)
del arr1
del arr2
print "done deleting arr1 arr2"
start = timer()
clf = LinearDiscriminantAnalysis()
clf.fit(X, y)
end = timer()
del X
del y
print "Time it took to train:"
print(end - start)
print "Time it took to Predict:"
test.append(randomarr())
test.append(randomarr())
test.append(randomarr())
test.append(randomarr())
start = timer()
print "class prediction";
print(clf.predict(test))
end = timer()
print(end - start)
print "decision function value"
#print test;
print (clf.decision_function(test))
示例2: RandomForestClassifier
# 需要导入模块: from sklearn.discriminant_analysis import LinearDiscriminantAnalysis [as 别名]
# 或者: from sklearn.discriminant_analysis.LinearDiscriminantAnalysis import decision_function [as 别名]
model = RandomForestClassifier(n_estimators=10, max_depth=3)
print "Random Forest"
test_model(model)
model_lda = LinearDiscriminantAnalysis()
print "LDA"
test_model(model_lda)
use_prediction = False
raw_test_data, test_labels = readDataMultipleFiles([3])
test_data_matrix, test_data_matrices, test_labels, test_labels_binary = buildMatricesAndLabels(raw_test_data, test_labels, scaling_functions)
test_predictions = []
for features in test_data_matrix:
if not use_prediction:
test_predictions.append(model_lda.decision_function([features])[0]) # score for classes_[1]
else:
test_predictions.append(model_lda.predict_proba([features])[0])
for i in range(target_count):
print sum(test_labels_binary[i])
thresholds_for_bci = multiclassRoc(test_predictions, test_labels_binary)
# model = SVC(C=1000, kernel="poly", degree=2)
# print "SVM"
# test_model(model)
# pickle.Pickler(file("U:\\data\\test\\5_targets\\model0.pkl", "w")).dump(model_lda)
# pickle.Pickler(file("U:\\data\\test\\5_targets\\model0_mm.pkl", "w")).dump(min_max)
# pickle.Pickler(file("U:\\data\\test\\5_targets\\model0_thresh.pkl", "w")).dump(thresholds_for_bci)
示例3: LinearDiscriminantAnalysis
# 需要导入模块: from sklearn.discriminant_analysis import LinearDiscriminantAnalysis [as 别名]
# 或者: from sklearn.discriminant_analysis.LinearDiscriminantAnalysis import decision_function [as 别名]
spectraCal = np.delete(spectraCal, np.where(bbl == 0)[0], 1) # remove bad bands
# Read in validation spectral files
# libSpecValFile = libLocation + dateTag + '_transformed_spectral_library_validation_spectra.csv'
libSpecValFile = libLocation + dateTag + '_spectral_library_validation_spectra.csv'
spectraVal = np.loadtxt(libSpecValFile, dtype=object, delimiter=',') # Load in spectra - skips first line
metaSpecVal = spectraVal[:, 0:5] # save first 5 columns of spectra separately
spectraVal = np.delete(spectraVal, [0, 1, 2, 3, 4], 1) # remove the 5 columns of metadata in spectra
spectraVal = spectraVal.astype(np.double) # convert from string array to double array
spectraVal = np.nan_to_num(spectraVal) # there are values that are not finite, change them to zero
spectraVal = np.delete(spectraVal, np.where(bbl == 0)[0], 1) # remove bad bands
# Develop canonical discriminant variables
clf = LinearDiscriminantAnalysis() # http://scikit-learn.org/stable/modules/generated/sklearn.discriminant_analysis.LinearDiscriminantAnalysis.html#sklearn.discriminant_analysis.LinearDiscriminantAnalysis
clf.fit(spectraCal, metaCal[:, 15].astype(np.int))
cdaDecision = clf.decision_function(spectraVal)
cdaScore = clf.scalings_
cdaPredict = clf.predict(spectraVal)
calCDA = clf.transform(spectraCal)
valCDA = clf.transform(spectraVal)
# Calculate results from CDA development
regr = linear_model.LinearRegression()
x = metaVal[:, 15].astype(np.int).reshape(len(metaVal[:, 15]), 1)
y = cdaPredict.reshape(len(cdaPredict), 1)
linearResults = regr.fit(x, y) # http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html
plt.scatter(metaVal[:, 15].astype(np.int), cdaPredict)
plt.plot(metaVal[:, 15].astype(np.int), regr.predict(x))
plt.ylabel('Predicted')
plt.xlabel('Observed')
plt.title(dateTag)