美文网首页
randomforest

randomforest

作者: 还闹不闹 | 来源:发表于2020-06-23 15:23 被阅读0次
#!/usr/bin/python
# coding=utf-8
import numpy as np
import pandas as pd
from sklearn.model_selection import cross_val_score
from sklearn.datasets import make_blobs
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.tree import DecisionTreeClassifier

# 显示所有列
pd.set_option('display.max_columns', None)
# 显示所有行
pd.set_option('display.max_rows', None)
# 设置value的显示长度为10000,默认为50
pd.set_option('display.width',10000)
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
#
np.set_printoptions(linewidth=1000)

X, y = make_blobs(n_samples=10000, n_features=10, centers=100, random_state=0)
print(X.shape, y.shape)
print(type(X))
print(X[0:3])
print(y[0:3])


clf1 = DecisionTreeClassifier(max_depth=None, min_samples_split=2, random_state=0)
clf1.fit(X, y)
scores = cross_val_score(clf1, X, y)
print(scores.mean())


clf2 = RandomForestClassifier(n_estimators=10, max_depth=None, min_samples_split=2, random_state=0)
clf2.fit(X, y)
scores = cross_val_score(clf2, X, y)
print(scores.mean())


clf3 = ExtraTreesClassifier(n_estimators=10, max_depth=None, min_samples_split=2, random_state=0)
clf3.fit(X, y)
scores = cross_val_score(clf3, X, y)
print(scores.mean())


x1 = X[0:1]
print(type(x1))
print(x1[0:1][0])
x2 = [[6.46907649,4.25070317,-8.63694437,4.04478517,9.01725363,4.53587229,-4.67027643,-0.48172814,-6.44996141,-2.65984972]]
print(clf1.predict(x1[0:1]))
print(clf1.predict(x2))

相关文章

网友评论

      本文标题:randomforest

      本文链接:https://www.haomeiwen.com/subject/lzpcfktx.html