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


Python ExtraTreesClassifier.fit_transform方法代码示例

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


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

示例1: getSelectedValues

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import fit_transform [as 别名]
 def getSelectedValues(self):
     (train, trainLabels, test) = self.getScaledValues()
     
     selector = ExtraTreesClassifier(compute_importances=True, random_state=0)
     train = selector.fit_transform(train, trainLabels)
     
     return (train, trainLabels, test)
     test = selector.transform(test)
开发者ID:jreiberkyle,项目名称:Kaggle_Data-Science-London,代码行数:10,代码来源:prediction.py

示例2: ExtraTreesClassifier

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import fit_transform [as 别名]
import numpy as np
from sklearn import preprocessing as pp
from sklearn import cross_validation as cv
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.svm import SVC

workDir = r'C:\users\Akshay\Downloads\kaggle\\'

# Read data
train = np.genfromtxt(open(workDir + 'train.csv','rb'), delimiter=',')
target = np.genfromtxt(open(workDir + 'trainLabels.csv','rb'), delimiter=',')
test = np.genfromtxt(open(workDir + 'test.csv','rb'), delimiter=',')

# Scale data
train = pp.scale(train)
test = pp.scale(test)

# Select features
selector = ExtraTreesClassifier(compute_importances=True, random_state=0)
train = selector.fit_transform(train, target)
test = selector.transform(test)

# Estimate score
classifier = SVC(C=8, gamma=0.17)
scores = cv.cross_val_score(classifier, train, target, cv=30)
print('Estimated score: %0.5f (+/- %0.5f)' % (scores.mean(), scores.std() / 2))

# Predict and save
result = classifier.fit(train, target).predict(test)
np.savetxt(workDir + 'a.csv', result, fmt='%d')
开发者ID:akshayah3,项目名称:Kaggle,代码行数:32,代码来源:data_science_london.py

示例3: print

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import fit_transform [as 别名]
import numpy as np
import pandas as pd
from sklearn import preprocessing as pp
from sklearn.ensemble import ExtraTreesClassifier

print("Preparing the data")
train = pd.io.parsers.read_csv(r"D:\shared\datascience\phy_train_clean.csv", sep=',', header=0)
test = pd.io.parsers.read_csv(r"D:\shared\datascience\phy_test_clean.csv", sep=',', header=0)

test_index = test.Id
test = test.iloc[:,2:]

target = train.kind
train_index = train.Id
train = train.iloc[:,2:]

print("Preparing an Feature classifier")
selector = ExtraTreesClassifier(compute_importances=True, random_state=0)

print("Transforming the original dataset")
train = pd.DataFrame(selector.fit_transform(train, target), index = train_index)
test = pd.DataFrame(selector.transform(test), index = test_index)
train['kind'] = target

print("Storing the data...")
train.to_csv(r"D:\shared\datascience\phy_train.csv", sep=',')
test.to_csv(r"D:\shared\datascience\phy_test.csv", sep=',')
print("Job finished")
开发者ID:leonardodaniel,项目名称:phy-KDD2004,代码行数:30,代码来源:phy_clustering.py

示例4: main

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import fit_transform [as 别名]
def main():
	X =[]
	Y=[]
	featuresDB = Base(os.getcwd()+"\\Databases\\features.db")
	featuresDB.open()
	print "features open"
 
	for rec in featuresDB:
		vec = []
		vec.append(rec.f1)
		vec.append(rec.f3)
		vec.append(rec.f4)
		vec.append(rec.f5)
		vec.append(rec.f6)
		vec.append(rec.f7)
		vec.append(rec.f10)
		vec.append(rec.f11)
		vec.append(rec.f12)
		vec.append(rec.f13)
		vec.append(rec.f14)
		vec.append(rec.f15)
		vec.append(rec.f16)
		vec.append(rec.f17)
		vec.append(rec.f18)
		vec.append(rec.f19)
		vec.append(rec.f20)
		vec.append(rec.f21)
		vec.append(rec.f22)
		vec.append(rec.f23)
		X.append(vec)
		Y.append(rec.score)
	print "building classifier"	

	Y = np.array(Y)
	ybar = Y.mean()
	for i in range(len(Y)):
		if Y[i]<ybar: 
			Y[i]=1
		else:
			 Y[i]=2
	scaler = Scaler().fit(X)
	X = scaler.transform(X)
	
	X= np.array(X)
	Y=np.array(Y)

	skf = cross_validation.StratifiedKFold(Y,k=2)
	for train, test in skf:
		X_train, X_test = X[train], X[test]
		y_train, y_test = Y[train], Y[test]

	
	clf = ExtraTreesClassifier(n_estimators=8,max_depth=None,min_split=1,random_state=0,compute_importances=True)
	scores = cross_validation.cross_val_score(clf,X_train,y_train,cv=5)
	
	clf.fit_transform(X_train,y_train)
	print "Accuracy: %0.4f (+/- %0.2f)" % (scores.mean(), scores.std() / 2)
	print clf.feature_importances_

	y_pred =clf.predict(X_test)
	print	classification_report(y_test,y_pred)
	
	model=(scaler,clf)
	joblib.dump(model,'AestheticModel\\aestheticModel.pkl')
	
	print "Done"
开发者ID:Perchik,项目名称:RoD2,代码行数:68,代码来源:AestheticModel.py

示例5: PCA

# 需要导入模块: from sklearn.ensemble import ExtraTreesClassifier [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesClassifier import fit_transform [as 别名]
print test_data_array.shape
file_label.close()

# normalize the features in the train and test dataset
train_data_array_norm = preprocessing.scale(train_data_array)
test_data_array_norm = preprocessing.scale(test_data_array)

# run the module of PCA
#pca = PCA(n_components = 10)
#train_data_array_norm_pca = pca.fit_transform(train_data_array_norm, train_result_array)
#test_data_array_norm_pca = pca.transform(test_data_array_norm)
#print 'train data shape', train_data_array_norm_pca.shape

# tree-based feature selection
classifier = ExtraTreesClassifier()
train_data_array_norm_pca = classifier.fit_transform(train_data_array_norm, np.ravel(train_result_array))
test_data_array_norm_pca = classifier.transform(test_data_array_norm)
print 'train data shape', train_data_array_norm_pca.shape


## build SVM
# random shuffle
np.random.seed(0)
indices = np.random.permutation(len(train_result_array))

classifer = svm.SVC(C=20, gamma = 0.05)

# cross validation
scores = cv.cross_val_score(classifier, train_data_array_norm_pca, np.ravel(train_result_array), cv = 30)

开发者ID:huanqi,项目名称:kaggle-competitions,代码行数:31,代码来源:London2.py


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