Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何控制功能的数量[机器学习]?_Python_Machine Learning_Random Forest_Feature Extraction - Fatal编程技术网

Python 如何控制功能的数量[机器学习]?

Python 如何控制功能的数量[机器学习]?,python,machine-learning,random-forest,feature-extraction,Python,Machine Learning,Random Forest,Feature Extraction,我正在编写这个机器学习代码(分类),以便在两个类之间进行分类。我从为我的所有图像捕获一个功能开始 例如: (注:1和0用于标记) A类=[(4295046.0,1),(4998220.0,1),(4565017.0,1),(4078291.0,1),(4350411.0,1),(4434050.0,1),(4201831.0,1),(4203570.0,1),(4197025.0,1),(4110781.0,1),(40805668.0,1),(4276499.0,1),(4363551),(4

我正在编写这个机器学习代码(分类),以便在两个类之间进行分类。我从为我的所有图像捕获一个功能开始

例如: (注:1和0用于标记) A类=[(4295046.0,1),(4998220.0,1),(4565017.0,1),(4078291.0,1),(4350411.0,1),(4434050.0,1),(4201831.0,1),(4203570.0,1),(4197025.0,1),(4110781.0,1),(40805668.0,1),(4276499.0,1),(4363551),(4241573.0,1),(4470.0,1),(56823.0,1),(5572122.0,1),(4172122.0,1),(53891),(14970.0),(46901),(14971),(46901),(5682823.0,1),(4057898.0,1)、(4143981.0,1)、(3899129.0,1)、(3830584.0,1)、(3557377.0,1)、(3125518.0,1)、(3197039.0,1)、(3109404.0,1)、(3024219.0,1)、(3066759.0,1)、(272633.0,1)、(3507626.0,1)等)

B类=[(7179088.0,0),(7144249.0,0),(6806806.0,0),(5080876.0,0),(5170390.0,0),(5694876.0,0),(6210510.0,0),(5376014.0,0),(6472171.0,0),(7112956.0),(7356507.0,0),(9180030.0),(9183460.0),(9212517.0),(9055663.0),(9053709.0,0),(3067.0,890),(28890),(840.0),(440),(840),(840),(840),(905353709.0),(840),(9055663.0),(8752169.0, 0), (8779133.0, 0), (8756789.0, 0), (8990732.0, 0), (9027381.0, 0), (9090035.0, 0), (9343846.0, 0), (9518609.0, 0), (9435149.0, 0), (9365842.0, 0), (9395256.0, 0), (4381880.0, 0), (4749338.0, 0), (5296143.0, 0), (5478942.0, 0), (5610865.0, 0), (5514997.0, 0), (5381010.0, 0), (5090416.0, 0), (4663958.0, 0), (4804526.0, 0), (4743107.0, 0),(4898914.0,0)、(5018503.0,0)、(5778240.0,0)、(5741893.0,0)、(4632926.0,0)、(5208486.0,0)、(5633403.0,0)、(5699410.0,0)、(5748260.0,0)、(5869260.0,0)等]

/data is A and B combined

x = [[each[0]] for each in data]
y = [[each[1]] for each in data]
print (len(x), len(y))

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, 
random_state=42)
print (len(x_train), len(x_test))
print (len(y_train), len(y_test))

from sklearn.ensemble import RandomForestClassifier

clf = RandomForestClassifier(n_estimators=100, max_depth=2, random_state=0)
clf.fit(x_train, y_train)
问题:

如何更改以添加其他功能?添加功能时A和B的外观如何?我是否更改此行

clf = RandomForestClassifier(n_estimators=100, max_depth=2, random_state=0)
当使用两个功能时

我猜:

A级=[(4295046.0,secons功能,1),(4998220.0,secons功能,1),(4565017.0,secons功能,1),(4078291.0,secons功能,1),(4350411.0,secons功能,1),(4434050.0,1),…]
是这样吗?有更好的方法吗?

此型号不需要明确的功能数量。
如果类始终是数据中每个元组中的最后一个元素,则可以执行以下操作:

x = [[each[:-1]] for each in data]
y = [[each[-1]] for each in data]

“随机森林”的概念是,你有很多简单的模型,这些模型是你的平均值。这意味着,无论你有多少特征,你的树都不应该太深。如果你有很多特征,并且使用了很多树,你可以试着增加深度,但一般来说,对于随机森林,树的深度是应该是浅薄的。实验并尝试一下

例如:


在这个实验中,有+900个数据点和9个特征。他们测试了1到32之间的max_depth值,从结果来看,我认为大约5个是最好的。但这可能会因所讨论的数据集和特征而有所不同。

我理解。但是,我想看看添加另一个特征的效果,我也想了解如何在我的案例[Format]中引入多个功能。类是最后一个数字,功能是第一个数字。但是,如果我想添加另一个功能,我想在它们之间添加它吗?如何向模型引入另一个功能?是的,您只需在它们之间添加它。
x
将包括所有功能(即除最后一个数字外的所有数字,这是您所说的课程)。谢谢。我会试试这个