当前位置: 首页>>代码示例>>Python>>正文


Python LinearDiscriminantAnalysis.decision_function方法代码示例

本文整理汇总了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))
开发者ID:JavedZahoor,项目名称:phd-thesis-II-mattia,代码行数:32,代码来源:lda.py

示例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)
开发者ID:kahvel,项目名称:MAProject,代码行数:32,代码来源:test.py

示例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)
开发者ID:susanmeerdink,项目名称:CDA-LDA-Classification,代码行数:33,代码来源:CDA_development.py


注:本文中的sklearn.discriminant_analysis.LinearDiscriminantAnalysis.decision_function方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。