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


Python RandomForestClassifier.n_classes_方法代码示例

本文整理汇总了Python中sklearn.ensemble.RandomForestClassifier.n_classes_方法的典型用法代码示例。如果您正苦于以下问题:Python RandomForestClassifier.n_classes_方法的具体用法?Python RandomForestClassifier.n_classes_怎么用?Python RandomForestClassifier.n_classes_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.ensemble.RandomForestClassifier的用法示例。


在下文中一共展示了RandomForestClassifier.n_classes_方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Train1

# 需要导入模块: from sklearn.ensemble import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.RandomForestClassifier import n_classes_ [as 别名]
def Train1(X, y):
	rfc = RandomForestClassifier(n_estimators=10, oob_score=True)
	rfc.n_classes_ = 3
	model = rfc.fit(X, y)
	return model
开发者ID:Sapphirine,项目名称:Data-Analytics-of-Video-Popularity,代码行数:7,代码来源:RF.py

示例2: Train_Kfold

# 需要导入模块: from sklearn.ensemble import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.RandomForestClassifier import n_classes_ [as 别名]
def Train_Kfold(X, y, K):
	#y = np.array(y)
	kf = KFold(X.shape[0], n_folds = K)

	record = {}

	k = 0
	for train_index, test_index in kf:
		k = k + 1
		rfc = RandomForestClassifier(n_estimators=5, oob_score=True)
		rfc.n_classes_ = 3
		model = rfc.fit(X[train_index], y[train_index])
		pred = model.predict(X[test_index])
		count = 0
		#AB: predicted as "1" while really is "2"
		AA, AB, AC, BA, BB, BC, CA, CB, CC = 0,0,0,0,0,0,0,0,0
		TA, TB, TC, PA, PB, PC = 0,0,0,0,0,0
		for i in range(len(pred)):
			if pred[i] == '1' and y[test_index][i] == '1':
				AA = AA + 1
				PA = PA + 1
				TA = TA + 1
			if pred[i] == '1' and y[test_index][i] == '2':
				AB = AB + 1
				PA = PA + 1
				TB = TB + 1
			if pred[i] == '1' and y[test_index][i] == '3':
				AC = AC + 1
				PA = PA + 1
				TC = TC + 1
			if pred[i] == '2' and y[test_index][i] == '1':
				BA = BA + 1	
				PB = PB + 1
				TA = TA + 1
			if pred[i] == '2' and y[test_index][i] == '2':
				BB = BB + 1
				PB = PB + 1
				TB = TB + 1
			if pred[i] == '2' and y[test_index][i] == '3':
				BC = BC + 1
				PB = PB + 1
				TC = TC + 1
			if pred[i] == '3' and y[test_index][i] == '1':
				CA = CA + 1
				PC = PC + 1
				TA = TA + 1	
			if pred[i] == '3' and y[test_index][i] == '2':
				CB = CB + 1
				PC = PC + 1
				TB = TB + 1
			if pred[i] == '3' and y[test_index][i] == '3':
				CC = CC + 1
				PC = PC + 1
				TC = TC + 1		
			if pred[i] != y[test_index][i]:
				count = count + 1
		record[str(k)] = [count, AA, AB, AC, BA, BB, BC, CA, CB, CC, TA, TB, TC, PA, PB, PC, len(pred)]
	err, Aerr, Berr, Cerr = 0, 0, 0, 0
	for key in record:
		Aerr = Aerr + (record[key][2]+record[key][3])/float(record[key][13])
		Berr = Berr + (record[key][4]+record[key][5])/float(record[key][14])
		#Cerr = Cerr + (record[key][7]+record[key][8])/float(record[key][15])
		err = err + record[key][0]/float(record[key][16])
	err = err/float(K)
	Aerr = err/float(K)
	Berr = err/float(K)
	#Cerr = err/float(K)
	#err = float(count)/K
	#AA, AB, AC, BA, BB, BC, CA, CB, CC = float(AA)/K, float(AB)/K, float(AC)/K, float(BA)/K, float(BB)/K, float(BC)/K, float(CA)/K, float(CB)/K, float(CC)/K
	return (err, Aerr, Berr)
开发者ID:Sapphirine,项目名称:Data-Analytics-of-Video-Popularity,代码行数:72,代码来源:RF.py


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