1

Good day everyone! Id like to get a lot of diffrent results and see standard deviation. Here my code:

lr_score, lr_tune_params = auto_tune_lr_second(x_train, x_test, y_train, y_test)
print('Random state changing...')
for i in range(1, 151):
    LR = LogisticRegression(C=lr_tune_params[0], max_iter=lr_tune_params[1], penalty=lr_tune_params[2], random_state=i)
    LR.fit(x_train, y_train)
    pred = LR.predict(x_test)
    pr_money_lr.append(find_profit(confusion_matrix(y_test, pred)))
pr_money_lr = np.array(pr_money_lr)
lr_mean = pr_money_lr.mean()
lr_std = pr_money_lr.std()
print ([lr_mean - lr_std, lr_mean + lr_std])

where auto_tune_lr_second(x_train, x_test, y_train, y_test) is the same thing as GridSearch(), function find_profit(confusion_matrix(y_test, pred)) is hand-made metric for optimization which get confusion matrix and return some scalar result.

In every iteration i change random_state but i get the same results(the same confusion matrix). I tried to set diffrent random_states as a parameter in Logistic Regrassion and tried to set diffrent numpy.random.seed(). None of them worked. Do you have any ideas why i get the same results with diffrent random_states?

Kirill
  • 33
  • 7
  • see this [link](https://stackoverflow.com/questions/28064634/random-state-pseudo-random-numberin-scikit-learn) – M. Doosti Lakhani Sep 12 '18 at 10:18
  • Are you using `sklearn` library for `LogisticRegression`? and if you are, what is your `sklearn` library version? This problem was in `0.19.0` and solved in `0.19.1`. So check this [link](https://github.com/scikit-learn/scikit-learn/issues/10237) – M. Doosti Lakhani Sep 12 '18 at 10:23
  • My `sklearn` version is `0.19.2` – Kirill Sep 12 '18 at 11:56
  • I tested `random_state` in `train_test_split` from `sklearn.model_selection` and also I tested on `RandomForestClassifier` from `sklearn.ensemble`. In both, when I change the `random_state` value, the result changes. Please check my code in my [github repo](https://github.com/Nikronic/Machine-Learning-Models/tree/master/Part%203%20-%20Classification/Section%2013%20-%20Random%20Forest%20Classification). And please provide your full code so I can test yours. Thanks for any star and upvote. – M. Doosti Lakhani Sep 12 '18 at 16:15

0 Answers0