How to Output a Value with Changed Random State

Asked 2 months ago, Updated 2 months ago, 6 views

I am outputting while changing random state in machine learning.
For example, is it possible for the following program to output random state from 0 to 20 all values?
Currently, I manually change from 0 to 20 and output it on the jupyter notebook one by one.

import numpy as np
from sklearn.enable import RandomForestClassifier
from sklearn.model_selection import LeaveOneOut
from sklearn.model_selection import cross_val_score

forest=RandomForestClassifier(n_estimators=100, random_state=0)
data=np.loadtxt('mh.csv', delimiter=',',', skiprows=1, dtype=float)
labels=data [:,0:1]
features=data [:,1:]
loo=LeaveOneOut() 
scores=cross_val_score(forest, features, labels.ravel(), cv=loo) 

print('Mean accuracy: {:3f}'.format(scores.mean()))) 

python numpy

2022-09-30 11:07

1 Answers

The task is to repeat almost the same thing over and over again, so you can do it using the for statement."In addition, this time, ""repeat while changing from 0 to 20"", so simply change one variable from 0 to 20 and repeat it."

For example, the program below prints numbers from 0 to 20.

for i in range(0,21):
    print(i)

This problem can be solved by changing the contents of the for statement in the same way.

Perhaps they are learning machine learning while copying and pasting Python programs from some kind of material.If you want to do something more advanced, you have to understand the programming language Python itself to a certain extent, so I think it will be easier to do any Python tutorials in the future.


2022-09-30 11:07

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.