种子选项:在Python中使用不同的机器学习包
我想知道下面的代码是否会给出相同的结果。更具体地说,如果种子选项:在Python中使用不同的机器学习包,python,scikit-learn,graphlab,Python,Scikit Learn,Graphlab,我想知道下面的代码是否会给出相同的结果。更具体地说,如果random_state=0与seed=0相同: -使用sklearn: from sklearn.cross_validation import train_test_split x = data['x'] y = data['y'] X_train,X_test,Y_train,Y_test = train_test_split(x,y,test_size = 0.2,random_state = 0) -使用图形选项卡: impor
random_state=0
与seed=0
相同:
-使用sklearn
:
from sklearn.cross_validation import train_test_split
x = data['x']
y = data['y']
X_train,X_test,Y_train,Y_test = train_test_split(x,y,test_size = 0.2,random_state = 0)
-使用图形选项卡
:
import graphlab
train_data,test_data = data.random_split(.8,seed=0)
据我所知,
graphlab
在3.4版中不可用(如果我错了,请纠正我),因此我无法检查自己。谢谢不,这两个库对这两个代码段给出的结果不同。scikit学习函数使用随机排列来洗牌数据,然后将数据分割成所需的分数。SFrame.random_split
方法不同;它根据指定的分数从原始数据中随机采样行
不仅如此,两个库的随机数生成器是不同的,因此将随机状态和种子设置为相同的值不会产生任何效果
我用GraphLab Create 1.7.1和Scikit learn 0.17验证了这一点
import numpy as np
import graphlab as gl
from sklearn.cross_validation import train_test_split
sf = graphlab.SFrame(np.random.rand(10, 1))
sf = sf.add_row_number('row_id')
sf_train, sf_test = sf.random_split(0.6, seed=0)
df_train, df_test = train_test_split(sf.to_dataframe(),
test_size=0.4,
random_state=0)
SFU列车
为:
+--------+-------------------+
| row_id | X1 |
+--------+-------------------+
| 0 | [0.459467634448] |
| 4 | [0.424260273035] |
| 6 | [0.143786736949] |
| 7 | [0.0871068666212] |
| 8 | [0.74631952689] |
| 9 | [0.37570258651] |
+--------+-------------------+
[6 rows x 2 columns]
而df_列车
看起来像:
row_id X1
1 1 [0.561396445174]
6 6 [0.143786736949]
7 7 [0.0871068666212]
3 3 [0.397315891635]
0 0 [0.459467634448]
5 5 [0.033673713722]
绝对不一样