我有一个作业,我计划使用机器学习(特别是监督学习,比如决策树)。最终的代码将在教学助理的pc上运行,该pc没有安装scikit learn或其他外部库。
因此,我需要从头开始编写决策树分类器之类的东西,或者在本地使用外部库,并存储最终的算法。
总而言之:当给定一组标记的训练数据时,如何在python代码中存储最终算法,而不依赖外部库在未来运行最终算法?
例如,决策树可以分解为一系列if/then语句,我想生成这些if/then语句并存储它们,这样它就可以在除了python之外什么都没有安装的计算机上运行。
关于如何实现这一点,最好的建议是什么?如果这是在错误的论坛,请告知。
发布于 2015-03-10 12:53:04
您可以使用Python随机森林包sklearn.ensemble,如下所示:
# Import the random forest package
from sklearn.ensemble import RandomForestClassifier
# create a random forest object with 100 trees
forest = RandomForestClassifier(n_estimators = 100)
predictors = [[0, 0], [1, 1]]
response = [0, 1]
# fit the model to the training data
forest = forest.fit(predictors, response)
# you can reuse the forest model you built to make predictions
# on other data sets
test_data = [[0, 1], [1, 0]]
output = forest.predict(test_data)请注意,我在这里导入了RandomForestClassifier,但您也可以使用RandomForestRegressor,以便在回归模式下运行随机森林。
https://stackoverflow.com/questions/28956303
复制相似问题