Seed Options: Using Various Machine Learning Packages in Python

I was wondering if the following codes would give the same results. More specifically, if it random_state=0matches seed = 0:

-Use 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)

-Use graphlab:

import graphlab
train_data,test_data = data.random_split(.8,seed=0)

As far as I know, it is graphlabnot available in version 3.4 (correct me if I am wrong), so I could not verify myself. Thanks

+4
source share
1 answer

, . scikit-learn , . 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)

sf_train:

+--------+-------------------+
| 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]

while df_train :

   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]

.

+3

Source: https://habr.com/ru/post/1620584/


All Articles