本文整理汇总了Python中sklearn.ensemble.RandomForestClassifier.evt_predict方法的典型用法代码示例。如果您正苦于以下问题:Python RandomForestClassifier.evt_predict方法的具体用法?Python RandomForestClassifier.evt_predict怎么用?Python RandomForestClassifier.evt_predict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.ensemble.RandomForestClassifier
的用法示例。
在下文中一共展示了RandomForestClassifier.evt_predict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runTest
# 需要导入模块: from sklearn.ensemble import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.RandomForestClassifier import evt_predict [as 别名]
def runTest(size, trees, features, test):
'''for i in range(10):
foldX_train, foldX_test, foldy_train, foldy_test = train_test_split(X,y)
print("train size: " + str(foldy_train.size))
print("test size: " + str(foldy_test.size))
model = RandomForestClassifier(n_estimators = trees, max_features = features, min_samples_leaf = 5, oob_score = False)
model.fit(foldX_train,foldy_train)
for i in y_train:
if i not in classes:
classes.append(i)
model.evt_predict(X_test[test])'''
model = RandomForestClassifier(n_estimators = trees, max_features = features, min_samples_leaf = 5, oob_score = False)
model.fit(X_train,y_train)
fit(model, n_classes)
global min_threshold
global average_threshold
global product_threshold
classes = []
for i in y_train:
if i not in classes:
classes.append(i)
X_tests = None
y_tests = None
unknown = []
for i in range(10):
if i not in train_classes and i not in validate_classes:
unknown.append(i)
print train_classes
print validate_classes
print unknown
print train_classes + unknown[:test]
for i in train_classes + unknown[:test]:
if X_tests == None:
X_tests = X_test[i]
y_tests = y_test[i]
else:
X_tests = np.vstack((X_tests, X_test[i]))
y_tests = np.append(y_tests, y_test[i])
og_score = model.score(X_tests,y_tests)
print("random test: " + str(og_score))
predictions, pertinence = model.evt_predict(X_tests)
total = 0
min_correct = 0
average_correct = 0
product_correct = 0
min_out = 0
average_out = 0
product_out = 0
min_inn = 0
average_inn = 0
product_inn = 0
counter1 = 0
counter2 = 0
points_in = []
points_out = []
for i in range(len(predictions)):
total += 1
if pertinence[i][0] > min_threshold:
if predictions[i] == y_tests[i]:
min_correct += 1
else:
if y_tests[i] not in classes:
min_correct += 1
if pertinence[i][1] > average_threshold:
if predictions[i] == y_tests[i]:
average_correct += 1
else:
if y_tests[i] not in classes:
average_correct += 1
if pertinence[i][2] > product_threshold:
if predictions[i] == y_tests[i]:
product_correct += 1
else:
if y_tests[i] not in classes:
product_correct += 1
if y_tests[i] not in classes:
points_out.append(i)
min_out += pertinence[i][0]
average_out += pertinence[i][1]
product_out += pertinence[i][2]
counter1 += 1
else:
points_in.append(i)
min_inn += pertinence[i][0]
average_inn += pertinence[i][1]
product_inn += pertinence[i][2]
counter2 += 1
if counter2 > 0:
min_pertinence = min_inn/ float(counter2)
average_pertinence = average_inn/ float(counter2)
product_pertinence = product_inn/ float(counter2)
min_deviance = 0
average_deviance = 0
product_deviance = 0
for i in points_out:
min_deviance += (pertinence[i][0] - min_pertinence) ** 2
#.........这里部分代码省略.........